What is wrong with this mongoose aggregation?
The difference is that Mongoose will cast query values according to the model's defined schema for find
, but not for aggregate
.
This is noted in the docs here:
Mongoose does not cast pipeline stages.
Which explains why using { date: new Date(now.startOf('day')) }
works, as that's exactly the sort of manual casting you have to do with aggregate
.