Get newly added document first from collections.

Skip to first unread message

victor fienkelstein

Jun 17, 2021, 10:27:59 PM6/17/21
to MongoEngine Users
Hey Folks,
I am new to mongoengine and working on one flask app in that I need the data in descending order like newly added data show first.
I have a model name User
class User(db.Document):
    name = db.StringField()
     age = db.IntField()

I am querying like this :-  data = userdb.objects()
I am getting data in ascending order, but i need in descending order. 
Can anyone please tell me how to do .

ThankYou :)

Paulo Cauca

Jun 18, 2021, 8:29:00 AM6/18/21
Hey Victor ,

Try put data = userdb.objects().order_by('-name') 

 The order may be specified by prepending each of the keys by a "+" or
        a "-". Ascending order is assumed if there's no prefix.

        If no keys are passed, existing ordering is cleared instead.

        :param keys: fields to order the query results by; keys may be
            prefixed with "+" or a "-" to determine the ordering direction.

You received this message because you are subscribed to the Google Groups "MongoEngine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit

victor fienkelstein

Jun 20, 2021, 8:34:14 AM6/20/21
to MongoEngine Users
Reply all
Reply to author
0 new messages