I saw in official MongoDB docs that you can use aggregate on update. How can we do this in mongoose. Thanks.
https://docs.mongodb.com/manual/reference/operator/aggregation-pipeline/#stages-available-for-updates
Unfortunately this is a more significant undertaking than we thought. In order to work around the fact that Mongoose currently doesn't support pipelines in updateOne()
, you need to use Model.collection.updateOne()
to bypass Mongoose's casting. We're working on a fix and should have one out in the next 6 weeks :+1:
@vkarpov15 Will this fix also allow for aggregation updates in Model.updateMany? The mongodb driver allows for this. Thank you.
@florianbepunkt yes it will. The caveat is that Mongoose will not cast properties aggregation pipelines, even in updateMany()
. So if you choose to use aggregation update stages, you're on your own for casting values.
Most helpful comment
@florianbepunkt yes it will. The caveat is that Mongoose will not cast properties aggregation pipelines, even in
updateMany()
. So if you choose to use aggregation update stages, you're on your own for casting values.