How to sort a collection by date in MongoDB?

后端 未结 10 2054
失恋的感觉
失恋的感觉 2020-12-07 14:27

I am using MongoDB with Node.JS. I have a collection which contains a date and other rows. The date is a JavaScript Date object.

How can I sort this col

10条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 15:00

    collection.find().sort('date':1).exec(function(err, doc) {});
    

    this worked for me

    referred https://docs.mongodb.org/getting-started/node/query/

提交回复
热议问题