I'm trying to use PyMongo to select the most recent 6 entires in a DB sorted by Unix time. I want to avoid having to use cursors, so have been using the parameters in the find() method. The desired result in a Mongo query is below:
db.pings.find().sort({ serverTime: 1 }).limit(6)
In PyMongo, I'm doing the below:
pings = pings.find({'sessionId':sessionId}, sort=[('serverTime', pymongo.DESCENDING)], limit=6)
I've seen similar questions (such as this: pymongo sort() limit() different?) which don't specifically corespond to PyMongo. Please can someone confirm to me that the above will sort the results before it selects the top 6, rather than selecting the top 6 and then sorting?
Thanks,
Sam