Hello,
I fear as newbie I’m missing something really obvious but no amount of googling, including searching the forum is helping… hence why I think I might be barking up the wrong tree.
I’m ‘simply’ trying to find documents where a field called timestamp (I now know that was a bad name) is later/newer than a calculated unixtime. My documents all follow this format:
{
"objectClass": "Trunks",
"timestamp": "1601590491",
"Trunk": "Trunk_External",
"Calls": 0,
"Call Rate": 0,
... blah blah...
}
I’m trying to do something like this:
db.collection.find({
timestamp: { $gt: (new Date()-12345).getTime() }
})
Obviously the ‘12345’ could be any number of seconds/milliseconds and then I’d get all the documents returned with a “timestamp” after that calculated date/time.
I’ve tried so many things I’m not sure if it is syntax error or non-existent function. I’m not even sure getTime() is allowed in a MongoDB query, but after several hours I must seek help before time runs out and I look at extracting the whole dataset and then parsing it outside MongoDB!
Has anyone tried using and comparing unixtimes in MongoDB, or is it really just a very bad date format to try and use? Cheers!!