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.
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)
Short question, short answer: you can achieve this with sort()
and limit()
© 2022 - 2024 — McMap. All rights reserved.