Mongoengine gets last ()

In django, how to get the last instance of a query set if I use MongoEngine

Usually we perform

Users.objects.latest('id') 

But I can not use latest in MongoEngine.

;). I am stuck.

I did not find a solution here. but I implemented. What do you think about below

 Users.objects.all().order_by('-id').limit(1)[0] 

This will return the last instance.

and also fixed the problem by passing it mongoenngine.

https://github.com/anishmenon/mongoengine/

You can install it and use

  Users.objects.latest('id') 
+7
python django mongodb pymongo mongoengine
source share
1 answer

You can do:

 Users.objects.order_by('-id').first() 
+7
source share

All Articles