What is the ‘proper way’ to retrieve most recent N items from the database?
from tutorial and mongodb documentations it seems (besides using range queries)
db.collection.find(skip = 0, limit=N, sort=[("_id", -1)])
is it right?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your syntax doesn’t really seem quite right there.
Should do what you would expect.
Python and pymongo support simple chaining.
NOTE
Sorting on
_iddoes not necessarily yield the “most recent” item.