mongodb remove all dates less than specified

前端 未结 4 1113
孤独总比滥情好
孤独总比滥情好 2021-01-02 06:50

I have the following data.

{
    deviceID: 186,
    date: \"2014-3-15\"
}
{
    deviceID: 186,
    date: \"2014-3-14\"
}
{
    deviceID: 186,
    date: \"201         


        
4条回答
  •  礼貌的吻别
    2021-01-02 07:33

    Its because the date field you are querying on is a string filed and not a Date(). In your mongo documents instead of a custom date string, insert javascript date objects into date field.

    like

    { deviceID: 186,,"date": new Date(2012, 7, 14) }
    

    and when you execute the remove do it like

    db.coll.remove({date:{$lte:new Date(2012, 7, 14)}})
    

提交回复
热议问题