Using .sort with PyMongo



  • 1 Answer(s)

    For that the sort should be a list of key-direction couple

    db.test.find({"number": {"$gt": 1}}).sort([("number", 1), ("date", -1)])
    
    

    The following statement is ,The reason why this has to be a list is that the ordering of the arguments matters and dicts are not ordered in Python.

     

    Answered on January 11, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.