Mongoose / mongoDB - How to sort by string?
MongoDB can't sort by numbers stored as String. Here is the workaround
[ { "$addFields": { newId: { $toInt: "$_id" } } }, { "$sort": { newId: 1 } }, { $project:{ newId:0 } }]
Working Mongo playground