Compare 2 dates in mongo find method

前端 未结 4 1732
一向
一向 2021-01-03 09:57

I have mongo documents containing a last_active date and a created date. I would like to search for all documents where the day of last_active is not equal

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-03 10:39

    One way to do this would be with $where http://docs.mongodb.org/manual/reference/operator/query/where/ Or you can use aggregate query. Something like this (improve to add fields that you need to retrieve):

    db.dates.aggregate({$project: { created: 1, last_active: 1, are_diff: {$ne: ["$created", "$last_active"]}}}, {$match: {are_diff: true}})
    

提交回复
热议问题