How to get the last N documents with a mangoid?

I found some information to accomplish this in mongoDB, but I need it with mongoid. So I can do something like:

User.last(7000).each do ...

I use:

  • MongoDB Shell Version: 2.4.3

  • Mongoid 2.6.0

Thanks!

+8
ruby mongodb mongoid
source share
1 answer

Now I found a solution from mongoid origin :

 User.all.desc('_id').limit(7000) 

Sorts users in descending order according to identifier.

+20
source share

All Articles