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.
.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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With