Sort in multiple fields aggregate

Hello guys.I have a problem in sorting by multiple fields .
My query is this:


        "$match": {
            "first": {"$gte": datetime.strptime("2010-01-01 00:00:00", "%Y-%m-%d %H:%M:%S"),
                          "$lte" :datetime.strptime("2020-12-31 00:55:00", "%Y-%m-%d %H:%M:%S")}
    { "$unwind": "$samples" },

        "$group": {
                "date": {"$dateToString": { "format": "%Y-%m-%d ", "date": "$first" }},
      "avg_id9": {
                "$avg": "$samples.id9"
        "$project": {
            "_id": 0,

    {"$sort": {"day": -1,"id1313":1}}


When i sort only with day everything works fine,but when i add the second field to sort the output gives me this message Sort exceeded memory limit of 104857600 bytes, but did not opt in to external sorting.
What should i do?
Thanks in advance!

Did you tried passing {allowDiskuse:true} option in aggregation??

|allowDiskUse|boolean|Optional. Enables writing to temporary files. When set to true , aggregation stages can write data to the _tmp subdirectory in the dbPath directory.

Starting in MongoDB 4.2, the profiler log messages and diagnostic log messages includes a usedDisk indicator if any aggregation stage wrote data to temporary files due to memory restrictions.