Find all documents within last n days

前端 未结 2 1473
野的像风
野的像风 2020-11-30 13:44

My daily collection has documents like:

..
{ \"date\" : ISODate(\"2013-01-03T00:00:00Z\"), \"vid\" : \"ED\", \"san\" : 7046.25, \"izm\" : 12         


        
2条回答
  •  有刺的猬
    2020-11-30 14:28

    I just tested the following query against your data sample and it worked perfectly:

    db.datecol.find(
    {
        "date": 
        {
            $gte: new Date((new Date().getTime() - (15 * 24 * 60 * 60 * 1000)))
        }
    }
    ).sort({ "date": -1 })
    

提交回复
热议问题