[SERVER-11537] Incosistent behavior with $or and $elemMatch Created: 03/Nov/13 Updated: 10/Dec/14 Resolved: 08/Aug/14 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying, Write Ops |
| Affects Version/s: | 2.4.8, 2.6.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | NOVALUE Mitar | Assignee: | David Storch |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Mac OS X 10.7.5. |
||
| Issue Links: |
|
||||||||||||||||||||||||||||
| Operating System: | ALL | ||||||||||||||||||||||||||||
| Steps To Reproduce: | If you do queries:
I would expect that the second update will remove slug from second a == 1 array element. But it does not. On the other hand, if I run:
Second slug is correctly removed. |
||||||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||||||
| Description |
|
There seems to be inconsistency when using $or in combination with $elemMatch. See steps to reproduce. |
| Comments |
| Comment by David Storch [ 08/Aug/14 ] | |||||
|
Hi mitar, Thanks very much for reporting this issue. We have identified this to be a duplicate of For both positional projections and positional updates, the query system must identify the array element to which the projection or update should be applied. (Both uses of the "$" operator share an implementation, which means that this issue affects projections as well as the positional update case reported here.) The problem is that when there are multiple predicates over the array being projected/updated, it is undefined which the query system should use to determine the positional match. Consider the example from the "Repro Steps" box above:
The query part of this update has two predicates over "nested", as indicated below:
The query system arbitrarily chooses to use predicate #1 in order to determine the positional match, rather than predicate #2. This is the underlying cause of the behavior reported here. I'm going to resolve this ticket as a duplicate, but please feel free to reach out with any further questions or concerns. Best, | |||||
| Comment by NOVALUE Mitar [ 03/Nov/13 ] | |||||
|
And a similar query with $and works as well:
| |||||
| Comment by NOVALUE Mitar [ 03/Nov/13 ] | |||||
works as well. |