Should return "2022-05-09T00:00:00.000+00:00", "2022-05-31T00:00:00.000+00:00".
Because the range matches "2022-05-31T00:00:00.000+00:00" and "2022-05-09T00:00:00.000+00:00" is the previous one. How to do that with the aggregation framework?
The above indicates greater than or equal to "2022-05-25T00:00:00.000+00" (25th of May 2022). However, below you wrote:
Should return "2022-05-09T00:00:00.000+00:00", "2022-05-31T00:00:00.000+00:00" .
Because the range matches "2022-05-31T00:00:00.000+00:00" and "2022-05-09T00:00:00.000+00:00" is the previous one
The first date mentioned is "2022-05-09T00:00:00.000+00:00" (9th of May 2022). This is not greater than or equal to the initial date mentioned in your $match example.
Additionally, the “dates” mentioned inside the date array are string values. Is this expected? In the example below, without converting these values to dates using $toDate no documents are returned in the filteredDates array.
To clarify, can you advise on the expected / desired output documents?
In the meantime, please see the below example aggregation that uses $filter to retrieve the “dates” within the "dates" array that are greater than or equal to ISODate("2022-05-25T00:00:00.000Z":
$toDate (Used for converting string values inside the dates array)
Please test this thoroughly in a test environment to ensure it meets your requirements / suits your use cases as I have only used the sample document you provided.