ISO Date function working on date having 0 in time but not with proper time

67 views Asked by At

I am trying to search some data in collection so i add {dCreatedAt: ISODate('2022-11-16')} in filter so i have two data having following values in db

dCreatedAt: 2022-11-16T00:00:00.000+00:00,
dCreatedAt: 2022-11-15T13:31:18.513+00:00

Filter showing only first data not the second one.

1

There are 1 answers

4
nimrod serok On

If you really want, you can use an aggregation pipeline:

db.collection.aggregate([
  {
    $match: {
      $expr: {
        $eq: [
          {$dateTrunc: {date: "$dCreatedAt", unit: "day"}},
          {$dateFromString: {dateString: "2022-11-16"}}
        ]
      }
    }
  }
])

See how it works on the playground example