Reputation: 53843
I'm just learning how to use MongoDB by using MongoEngine from Python. Simply getting all users is done as follows:
User.objects
I now want to order the users on their creation date. In the MongoDB docs I found something about .sort(), but in the MongoEngine docs I can't find anything about sort. I also tried using the following:
User.objects.sort('created')
but this leads to an AttributeError: 'BaseQuerySet' object has no attribute 'sort'
.
So does anybody know how I can sort MongoDB results using MongoEngine? All tips are welcome!
Upvotes: 0
Views: 2700
Reputation: 3821
I think you're looking for this:
The function is order_by, not sort. The hyphen sets direction.
Upvotes: 3