Change Stream: watch aggregation filter

Hi!

when I am filtering the change stream by date in the aggregation query like that:

{ "end$date" : {"$lte" : "new Date()"}}

does the change stream reevaluate the new Date() all the time?
or the value stays final from the moment watch() function was executed?

Thanks!

Your "new Date()" is inside double quotes, so it is not even a Date, it is a string.

The value stay final from the moment watch() is called.

Thank you for you answer,

the aggregation was taken from my code as I send the pipeline as string argument,
and if would remove the double quotes the date will be final anyway,
so if I understand your point there isn’t any way to watch by current date and it could be only
filtered on the watch emitted events?

My point was that new Date() is evaluated once and at the time of the watch() call which was your original question.

My point was not to indicate that there is no way to watch by current date.

To watch for current date, nothing stops you from closing your watch of the previous date and open a new one with the current date when said date changes.

1 Like

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