.sort()
, in pymongo, takes key
and direction
as parameters.
So if you want to sort by, let’s say, id
then you should .sort("_id", 1)
For multiple fields:
.sort([("field1", pymongo.ASCENDING), ("field2", pymongo.DESCENDING)])
More Related Contents:
- How to import data from mongodb to pandas?
- Query Mongodb on month, day, year… of a datetime
- search by ObjectId in mongodb with pymongo
- Insert a Pandas Dataframe into mongodb using PyMongo
- Authenticate After Picking the Database
- Fast or Bulk Upsert in pymongo
- How to make a query date in mongodb using pymongo?
- Append item to MongoDB document array in PyMongo without re-insertion
- Append item to MongoDB document array in PyMongo without re-insertion
- How to Ignore Duplicate Key Errors Safely Using insert_many
- Getting Spark, Python, and MongoDB to work together
- How to convert a pymongo.cursor.Cursor into a dict?
- Using .sort with PyMongo
- How to continue insertion after duplicate key error using PyMongo
- How to run raw mongodb commands from pymongo
- ImportError: No module named objectid
- “Large data” workflows using pandas [closed]
- TypeError: ObjectId(”) is not JSON serializable
- mongodb: insert if not exists
- Pymongo keeps refusing the connection at 27017
- Why is PyMongo 3 giving ServerSelectionTimeoutError?
- JSON ValueError: Expecting property name: line 1 column 2 (char 1)
- How to get ordered dictionaries in pymongo?
- mongodb cursor id not valid error
- Delete every non utf-8 symbols from string
- String formatting: % vs. .format vs. f-string literal
- Subprocess changing directory
- How to execute Python scripts in Windows?
- thread starts running before calling Thread.start
- How to write PNG image to string with the PIL?