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

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


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)*11360990800000

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.