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

这一生的挚爱 提交于 2019-11-28 17:37:35
Adam Comerford

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!