vivek modi
vivek modi

Reputation: 812

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

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.

Upvotes: 0

Views: 71

Answers (1)

nimrod serok
nimrod serok

Reputation: 16033

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

Upvotes: 1

Related Questions