I have made a query that finds all entries where the date field is within the next minute:
import { addMinutes, format } from 'date-fns'
date: {
$gte: new Date(),
$lt: (addMinutes(new Date(), 1))
}
However, this only works if the date is also on the same day as today. Now, if I want this to work regardless of which day is in the date field, what should I do?
The usecase is the following: The date field is set to Date.now() when the document is created. I want to get all documents that would be created within a minute from now, if there was no year, month nor day. This should also wrap around hours and days, so if it's currently 23:59:30, I want do find all documents that were created on any day at 23:59:30 or later, OR before 00:00:30.
basically I would want to extract only the hour minute and second from my date field, and work with those. But I can't find a way to do it.
Here is an example document:
"_id": "5f2447d259aaf231d8dc1d3b",
"date": "2020-08-07T12:22:00.000Z",
"enabled": true,