Support for positional $ operator in Update
See original GitHub issueIt seems that mongo-java-server does not support the positional operator $ when an update is performed. I’m trying to run the following update, but it does not work in my tests (it works when I run the actual code):
Query query = new Query();
query.addCriteria(Criteria.where("myArray").elemMatch(
Criteria.where("identifier").is("theId").and("state").is("theState")));
Update update = new Update()
.set("myArray.$.identifier", newId)
.set("myArray.$.state", newState);
this.mongoTemplate.updateMulti(query, update, MyEntity.class);
The error message is: The positional operator did not find the match needed from the query.
Would it be possible to fix this? It would be nice, if I am able to use my already exiting test in the future 😉
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
$ (update) — MongoDB Manual
The positional $ operator identifies an element in an array to update without explicitly specifying the position of the element in the array....
Read more >MongoDB - Positional Operator ($) - GeeksforGeeks
MongoDB provides different types of array update operators to update the values of the array fields in the documents and positional ...
Read more >positional update operator with upsert - Stack Overflow
As D. SM said, you can use bulkWrite to do multiple operations in one go: const shopId = 0 collection.bulkWrite([ // Remove any...
Read more >Support positional $ operator with aggregation pipeline for ...
I want to update the data-value of the data block with "block-id" : ObjectId("5fd3ba7eb0b91523b424e614") for the document with "_id" ...
Read more >Added positional operator ($) support when updating ... - GitHub
Added positional operator ($) support when updating documents. #438. Open. HowlingGuineapig wants to merge 3 commits into louischatriot ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok, thanks for this hint. I’ll try to have a closer look soon
I’m also seeing this problem.
I think the issue may be caused by
DefaultQueryMatcher.checkMatchesElemValues
not recordinglastPosition
when looping:It does so in
DefaultQueryMatcher.checkMatchesAnyValue(Object queryValue, Collection<?> values)
which is why your test isn’t failing.In order to provoke the issue, you need to use
$elemMatch
in the query.