How do I select date in native mongodb query?

Viewed 78

I want to execute the following code using Metabase and MongoDB database:

[{
  "$project":{
    "incrementId":"$incrementId",
    "createdAt":"$createdAt"
  }
},
  {"$limit":1048576}
]

How do I select a specific date? Let's say i want to see results for 18.03.2021. I'd really appreciate any advice.

2 Answers

Try this one:

{
   $match: {
      createdAt: {
         $gte: ISODate("2021-03-18T00:00:00Z"),
         $lte: ISODate("2021-03-18T23:59:59.999Z"),
      }
   }
}

This should work

[
  {
    $match: { createdAt: {
      '$gte': ISODate("2019-11-21T00:00:40.294Z"),
      '$lt': ISODate("2019-11-21T25:59:59")
    }}
  },
  {
    "$project":{
      "incrementId":"$incrementId",
      "createdAt":"$createdAt"
    }
  },
    {"$limit":1048576}
]
Related