I am currently using python to preprocess my data into JSON and insert my data into the collection via nodejs: collection.insert(data, {safe:true}, function(err, result) {});
My queries will be executed using nodejs as well.
I previously used python datetime.datetime
to format my timestamps, and this is how my JSON is structured:
[{
"timestamp" : "2016-08-02 20:30:02",
"detail" : blah blah blah
},{
"timestamp" : "2016-08-02 20:33:23",
"detail" : blah blah blah
},
...
]
I was trying to query based on the timestamp, and according to a lot of posts such as this Create an ISODate with pyMongo, I am supposed to use ISODate
for my query. So one of my attempts is:
collection.findOne({ timestamp: new ISODate("2016-08-02T20:33:23.786Z")})
This one says that ISODate is undefined. So based on this post I changed my query to:
collection.findOne({ timestamp: new Date("2016-08-02T20:33:23.786Z")})
This one says record not found. How should I store my timestamps into JSON? Is new Date("2016-08-02T20:33:23.786Z")
the right way to retrieve my instance? Also, when mongodb query timestamps, will it look at exact hours and minutes as well? I want to find the exact year, month, day, hour, minute and second just like how my timestamp is stored.