We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Given the following document in collection:
{ "name" : "Tenant 1", "appAllocations" : [ { "appId" : "68e1cf5a-0253-4c4a-9bc1-1eb3f27d0902" , "maxUser" : 4 }, { "appId" : "1bb05dc0-3acf-41a3-a5c2-551db93187fb" , "maxUser" : 42 } ] }
When filtering it via $elemMatch and updating the entire embedded via positional operator $, the update failed:
$elemMatch
$
"$set" : { "appAllocations.$" : { "appId" : "68e1cf5a-0253-4c4a-9bc1-1eb3f27d0902", "maxUser" : 9 } }
Then the update failed:
org.junit.ComparisonFailure: Expected :{ "name" : "Tenant 1" , "appAllocations" : [ { "appId" : "68e1cf5a-0253-4c4a-9bc1-1eb3f27d0902" , "maxUser" : 9} , { "appId" : "1bb05dc0-3acf-41a3-a5c2-551db93187fb" , "maxUser" : 42}]} Actual :{ "name" : "Tenant 1" , "appAllocations" : [ { "appId" : "68e1cf5a-0253-4c4a-9bc1-1eb3f27d0902" , "maxUser" : 4} , { "appId" : "1bb05dc0-3acf-41a3-a5c2-551db93187fb" , "maxUser" : 42}]}
However, this works on real MongoDB.
Only update one field:
"$set" : { "appAllocations.$.maxUser" : 9 }
@Test public void testPositionalOperatorWithElemMatch2() { String random1 = UUID.randomUUID().toString(); String random2 = UUID.randomUUID().toString(); DBObject object = (DBObject) FongoJSON.parse("{ \"name\" : \"Tenant 1\", \"appAllocations\" : [ { \"appId\" : \"" + random1 + "\" , \"maxUser\" : 4} , { \"appId\"" + ": \"" + random2 + "\" , \"maxUser\" : 42}]}"); DBObject query = (DBObject) FongoJSON.parse("{ \"appAllocations\" : { \"$elemMatch\" : { \"appId\" : \"" + random1 + "\"}}}"); DBObject update = (DBObject) FongoJSON.parse("{ \"$set\" : { \"appAllocations.$\" : { \"appId\" : \"" + random1 + "\", \"maxUser\" : 9 }}}"); System.out.println("update: " + update); DBObject expected = (DBObject) FongoJSON.parse("{ \"name\" : \"Tenant 1\", \"appAllocations\" : [ { \"appId\" : \"" + random1 + "\" , \"maxUser\" : 9} , { \"appId\"" + ": \"" + random2 + "\" , \"maxUser\" : 42}]}"); UpdateEngine updateEngine = new UpdateEngine(); assertEquals(expected.toString(), updateEngine.doUpdate(object, update, query, false).toString()); }
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
Overview
Given the following document in collection:
When filtering it via
$elemMatch
and updating the entire embedded via positional operator$
, the update failed:Then the update failed:
However, this works on real MongoDB.
Workaround
Only update one field:
Reproduction
The text was updated successfully, but these errors were encountered: