Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB equivalent of SQL "TOP" [closed]

Select Top 10 a, b from users
equivalent sql query in MONGODB

As a part of jqgrid functionality to save the json data and retrieve json data from the DB, I needed this simple SQL query in MONGODB.

like image 724
Santosh Avatar asked Nov 09 '12 15:11

Santosh


1 Answers

.limit()

Example:

db.things.find().limit(10)

Documentation: http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%7B%7Blimit%28%29%7D%7D

As per the comment below, technically, you'd want to sort the collection too, so it would be:

db.things.find().sort({someField:1}).limit(10)
like image 196
Alex Avatar answered Sep 21 '22 22:09

Alex