How do you iterate through a pymongo cursor object in reverse? I tried using the reversed built-in but there was an error:
TypeError: object of type 'Cursor' has no len()
My code:
for document in reversed(cursor):
documents.append(document)
答案 0 :(得分:0)
Looks like cursor can't be reserved but I can specify in sort a negative value to return a cursor with values stored in reverse:
collection.find(query, {}).sort('some_field_to_sort_by' : -1)