[SERVER-14010] Use of $where within $elemMatch Created: 21/May/14 Updated: 04/Aug/17 Resolved: 21/May/14 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | JavaScript, Querying |
| Affects Version/s: | 2.4.9, 2.4.10, 2.6.0, 2.6.1 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Neil Lunn | Assignee: | David Storch |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||
| Operating System: | ALL | ||||||||||||||||||||
| Steps To Reproduce: | Set up a document with a sub-document in an array:
Attempt a JavaScript match as done by the poster:
Produces the error in 2.6:
Which clearly seems intentional, but in prior versions the query produces a matching result without throwing the error. |
||||||||||||||||||||
| Participants: | |||||||||||||||||||||
| Description |
|
Different behavior of $where within $elemMatch from 2.4 version to 2.6 the issue was raised in this question It is noted to the poster that they should not be using the type of query as shown as the results can be achieved by other means. This probably requires a documentation patch to cover the changed behavior. |
| Comments |
| Comment by Rodolphe [X] [ 04/Aug/17 ] |
|
I need to ask, what is the rationale behind this constraint ? For some reason, I have to write queries in plain JSON so using $where inside $elemMatch was very pratictal and without this, the queries I'm trying to write are just a pain. And as I read it on https://docs.mongodb.com/manual/core/server-side-javascript/, I can't inject javascript in mongoDb queries apart from top-level `$where`s or MapReduce. |
| Comment by David Storch [ 21/May/14 ] |
|
2.6 enforces that $where appears at the top level of the query document. The allowance of $where below $elemMatch in 2.4 was determined to be unintentional. Resolving as a duplicate of I have opened |