-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"update one" aggregation update with optimistic locking throws exception #4097
Comments
It would be great to have a minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem. |
I've modified one of the ReactiveMongoTemplateUpdateTest in order to reproduce the problem. You can reproduce so with the following unit test:
It will throw the exception. The unit test above is not a valid one. Purpose of this test was just to reproduce the behavior that I wasn't expected. The failure result is the following :
Best regards, |
Hey @mp911de @christophstrobl I have faced with same issue. Here is a simple POC with reproduce in tests: https://github.com/osadchuk-roman/mongo-optimistic-locking-with-aggregation-update-issue?tab=readme-ov-file. More details: When I'm trying to executed aggregation update with optimistic locking and there were no matched documents in
![]() |
@mp911de @christophstrobl are there any updates for this issue? |
Hi,
I was wondering if I used the aggregation update badly.
I'm currently using spring-data-mongodb 3.3.4.
In fact, update first throws an exception while update all doesn't because of the optimistic lock checking in the method doUpdate of ReactiveMongoTemplate.
In order to reproduce the exception, we need to do an aggregation update and specify a matching query that doesn't match any document. I currently have two stages in my aggregation pipeline.
The exception occurs while trying to get MappedUpdate from the entity before checking if it contains the version property in order to throw an OptimisticLockingFailureException. A "'name' must not be null" is thrown.
Above this method we can see that we make a difference between aggregation update and basic update. My suggestion would be to change the code as follows but didn't check it yet :
Change from :
to:
Moving the build of updateObj to the if block avoid building it when we know that query object doesn't contain the version property save some computation.
We may, as well, move it to the previous if condition if getting version property don't do any computation as follow :
As a workaround, since the match query target a document id, I used all instead of first and all works as expected since I don't use the optimistic locking in my case.
The text was updated successfully, but these errors were encountered: