steevej
(Steeve Juneau)
2
Rather than $dateSubstract and $now, which forces you to use $expr which prevents the use of the index, could you do the same using JS date:
d = new Date()
2024-04-20T14:51:56.111Z
d2 = new Date(d - 21*24*60*60*1000)
2024-03-30T14:51:56.111Z
With this your query would become
const day = 24 * 60 * 60 * 1000 ;
...
last_processed_time: { $gt : new Date( new Date() - 21*day ) }
Yes, new Date() on the client may differs from the server $$NOW, but for day related use-case it should not make a big difference. And without the $expr, the index should be used.