Search by ISODate with Wildcard?

im trying to find all records that have a date that contains 00:00:00 in the hour minute and second portion to find documents that errored out in our subscription service. Was trying to use this but its erroring out.

db.CustomerSubscriptions.find({"UpcomingOrders.NextOrderDate": ISODate("/.*00:00:00.*/")})

Hi @Chase_Russell1 ,

The regex is only working on strings in a regex syntax.

What you need is probably to use aggregation with $dateToParts operator and $match all the documents that answer this time:

[{$unwind: {
  path: "$UpcomingOrders"
}}, {$addFields: {
  dateParts: { $dateToParts :  { date :"$UpcomingOrders.NextOrderDate" }}
}}, {$match: {
  "dateParts.hour" : 0,
  "dateParts.minute" : 0,
  "dateParts.second" : 0
}}]

Thanks,
Pavel

3 Likes

Thank you Pavel, I appreciate that!

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.