I'm currently facing a problem to export using the tool mongoexport.
Impossible de to create a date from a timestamp in my query :
db.getCollection('FooBarBarFoo').find({"actKey":"foobar","dt":{$gt:new Date('1434907890000')}})
Here some tests I made :
mongo-aws-dev:SECONDARY> var testDate = new Date('1434907890000');
mongo-aws-dev:SECONDARY> testDate
ISODate("0NaN-NaN-NaNTNaN:NaN:NaNZ")
mongo-aws-dev:SECONDARY> var testDate = new ISODate('1434907890000');
mongo-aws-dev:SECONDARY> testDate
ISODate("1441-08-17T00:00:00Z")
mongo-aws-dev:SECONDARY> var testDate = new ISODate(1434907890000);
mongo-aws-dev:SECONDARY> testDate
ISODate("1441-08-17T00:00:00Z")
We can see that the timestamp in millesconds 1434907890000
corresponding to the date 6/21/2015, 7:31:30 PM
in my timezone is converted to some medieval times.
Where can I possibly get wrong and how, in shell script, can I pass the timestamp to mongo query ?
Wo, sorry, I've just find the problem.
I tested
Date(timestamp in string)
ISODate(timestamp in string)
ISODate(timestamp in number)
But I didn't test the last ... The right one :
Date(timestamp in number)
So the right query is :
db.getCollection('FooBarBarFoo').find({"actKey":"foobar","dt":{$gt:new Date(1434907890000)}})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With