I am writing a script where I need to fetch data from mongodb using python. I need to first sort data in descending order using timestamp field and take latest 100 documents and then again I need to sort those 100 documents based on using other fields (pin_code and timestamp). Here is the code:
cursor = db.col.find().sort([("timestamp", pymongo.DESCENDING)]).limit(100)
cus = cursor.sort([("pin_code", pymongo.ASCENDING),("timestamp",pymongo.DESCENDING)])
I am expecting that second cursor should return sorted data from first cusor but its NOT returning the expected result. I know mongodb find() and sort() function return cursor but can i use that cursor as an input to other cursor?
PS: I am using pymongo module