Search code examples
mongodbdatetimestampsubtraction

Mongodb : convert and sort date to timestamp


I have a database in Mongodb 3.6, with a field "date.created" in ISODate (example : 2020-12-08T10:41:23.000+00:00) I want to find only results greater than 1607383475.

I tried this command but it doesn't seem to work...

{
  "$expr": {
    "$gt": [
      { "$subtract": ["$date.created", new Date("1970-01-01")] },
      1607383475
    ]
  }
}

Thank you for your help !


Solution

  • DSM is right, subtract is in milliseconds. I just had to convert my filter (*1000)...