Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

querying ISODate from unix timestamp in MongoExport

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 ?

like image 838
Thomas Leduc Avatar asked Feb 09 '23 17:02

Thomas Leduc


1 Answers

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)}})

like image 98
Thomas Leduc Avatar answered Feb 12 '23 15:02

Thomas Leduc