Skip to content

Instantly share code, notes, and snippets.

@sandheepg
Created August 1, 2017 07:02
Show Gist options
  • Save sandheepg/d7022c7fdba20dfb0d7ac3c25ff7c1c4 to your computer and use it in GitHub Desktop.
Save sandheepg/d7022c7fdba20dfb0d7ac3c25ff7c1c4 to your computer and use it in GitHub Desktop.
Last N records from MongoDB collection

If you want the last 5 records of a collection with latest coming first

db.getCollection('collection-name').find().limit(5).sort({$natural:-1})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment