Mongoexport using $gt and $lt constraints on a date range

前端 未结 1 1475
太阳男子
太阳男子 2020-12-13 07:54

I am trying to get the orders made for a certain day from my mongodb using the following mongoexport call:

mongoexport --db store --collection user_data --quer

相关标签:
1条回答
  • 2020-12-13 08:47

    The issue here is how you are representing the dates, they need to be passed in as Date types and in epoch format. Try this instead:

    mongoexport --db store --collection user_data --query '{"order.created_order":{$gt:new Date(1360040400000),$lt:new Date(1360990800000)}, "order.status" : "paid"}' --out ordersfeb6.json
    

    If you are looking to convert ISODate to epoch, just call date in the shell, something like this:

    > new Date(2013,01,16)*1
    1360990800000
    

    Then to verify:

    > new Date(1360990800000)
    ISODate("2013-02-16T05:00:00Z")
    

    Update: As noted in the comments by imcaptor, the Month is zero based (0 = Jan, 11 = Dec) in the Date constructor, not something most will expect, and easy to forget. I passed in 01 in the example above and got a February date, as you can see in the ISODate from the verification.

    0 讨论(0)
提交回复
热议问题