I have a collection I am trying to dump out within a date range. I’ve got a query working for ALL rows, and also have it working with $date: 1058715 (numerical) but that never outputs anything I’m guessing because it doesn’t match any rows in that conditional.
My dates in monog are stored as ISODATE(yadayada), so can I still query with $date: (numerical value)?
I created a date in the shell and got its value then using that numerical value.
Heres my working query , which outputs no rows
sudo bin/mongodump --db myDB --collection myColl -q '{"reading_date" : { "$gte" : { $date:1341230400000}}}' --out - > dump/myDB /will.bson
But I think I need
sudo bin/mongodump --db myDB --collection myColl -q '{"reading_date" : { "$gte" : new Date(2012,05,01)}}' --out - > dump/myDB /will.bson
If you are storing a date, you can compare it to javascript date in the mongo shell like this:
db.coll.find({mydate:{$gt:new Date(2012,0,1)}})Note that in js months are zero-based so the above represents January 1st 2012.
Since you need to pass this to mongodump, use this syntax instead:
Reference: http://www.mongodb.org/display/DOCS/Mongo+Extended+JSON