-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Update array doc - mention that the array field must appear last in the query argument #997
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
Conversation
Discovered that if there is any ambiguity with fields in the query argument, the array element that is identified will not be updated. Unless the specific array field that identifies the array element is the last item in the query argument.
Hi sperelson -- For instance, given a collection with the following document
The following query will match myField because myField has an element with the field _id = 'kay' and another element with the field a = 10, so as a whole myField matches.
More importantly, for your use case at hand, the ordering of the query does not guarantee that the right element is updated. For instance, I ran the following in sequence (I edited down the document for clarity sake)
I ran your first update statement with the "Another" condition as the first instead of last:
As you can see, in my collection, the update statement updated the 4th element
So, I believe the ordering of the query conditions are not quite coupled to which element will be selected to update. But as you correctly figured out yourself, using $elemMatch ensures that the query finds the element in the array that matches all the array element conditions. I'm going to close this pull request; however, I will definitely add explanation of the behavior regarding arrays. Thanks again for taking the time to work through this. Much appreciated. Regards, Kay |
* DOCS-15182 BACKPORT loadRoutingTableOnStartup * Staging fixes
* DOCSP-32752 Suppor for setting AWS region * edits * merge * another merge attempt * edit * edit on title * RM review * update links * default region * tech review note * change wanring msg * wording changed * change link (cherry picked from commit 65f4f5c) Co-authored-by: lindseymoore <71525840+lindseymoore@users.noreply.github.com>
Discovered that if there is any ambiguity with fields in the query argument, the array element that is identified will not be updated unless the specific array field that identifies the array element is the last item in the query argument.