Docs about Document#$where
#10583
Labels
docs
This issue is due to a mistake or omission in the mongoosejs.com documentation
Milestone
Hey. I have some legacy system, where the pattern model.findByID() -> change -> model.save() heavily used.
We have concurrency issues, and we decided to try to implement optimistic concurrency manually. I know the last mongoose version supports out of the box the optimisticConcurrency, but we cannot upgrade. And even if I could, I wouldn't use a single version flag because it will stress our system. We have too many fields on the object. that updated too often, even if they are not really related. As result, it will affect each update we have, including UI, and will make our life worse.
The idea is to introduce some additional field, like fooVersion, and increments it only when some specific fields were changed. I want to secure only a specific set of fields from concurrency issues. Don't care about other stuff for now...
This was my idea (pseudo):
I want to force the mongoose to generate under the hood the update with query (I assume it uses updateOne under the hood)
Then I wanted to capture results, and if zero docs were updated, throw concurrency error to the business flow, so the client can retry.
Cannot find any way to access the query from the pre('save') hook.
Also thinking how can I safely refactor code to use updateOne() explicitly instead of .save(), without refactoring the whole business logic. Do we have any API to force mongoose model provide me the "diff" it will use on save() so I can take it, and put manually to updateOne()?
Thanks!
p.s.
We use mongoose: v5.6.7
The text was updated successfully, but these errors were encountered: