[SERVER-77974] $all operator does not work on on $elemMatch Created: 10/Jun/23 Updated: 27/Oct/23 Resolved: 27/Oct/23 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Arkensor N/A | Assignee: | Backlog - Triage Team |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Assigned Teams: |
Server Triage
|
| Operating System: | ALL |
| Participants: |
| Description |
|
Hello, I am very new to mongo, so please forgive me if I am misusing the query syntax, but I have this situation that is either a bug or somebody please tell me how to correctly do it instead. Thank you. I am trying to find documents where any or all nested array elements must contain at least the values provided. This can normally be achieved easily with the $all operator. For example here:
The query
correctly matches because both are contained and
does not match. So far so good.
If you attempt the same for the nested arrays this stops working altogether.
The above does not match. I have found Stackoverflow questions about why on nested arrays all the operators start to fail but no one ever can explain why and they just use $elemMatch. But I do not know how I would translate my "all values must be in the array" to an $elemMatch. How I would say 1. ANY of the wordArrays must contain "Hello" and "World" -> would match I have prepared this little playground with the data in the hopes somebody knows how to achieve this. I would prefer if this could be solved all within the Find() stage, but if operations like this suddenly require the aggregation pipeline I am fine with that too. My approach for ANY match does not return any matches, and I do not understand why
I read it as wordArrays: does any element match: array contains "Hello" and "World". And that should have matched the document Thank you! |
| Comments |
| Comment by Edwin Zhou [ 27/Oct/23 ] |
|
Thank you for your patience and for following up that you've sent this inquiry to various channels. It appears that you received a response from the community forums, and we would like to encourage you to further pursue your investigation there. If that investigation leads you to believe that there is a bug, then we would investigate it here in the SERVER project. Kind regards, |
| Comment by Arkensor N/A [ 06/Jul/23 ] |
|
Dear eric.sedor@mongodb.com, thank you for your reply. I did indeed already open both a forum post and stack overflow issue about this a month ago, but neither resulted in any suitable workarounds. I was overall a bit disappointed to not get a single response on the forums, but I assume its simply because nobody knows how to deal with it - because it just is a bug and there is nothing else one could do. Please investigate this issue further in the correct expert developer team |
| Comment by Eric Sedor [ 05/Jul/23 ] |
|
For this issue we'd like to encourage you to start by asking our community for help by posting on the MongoDB Developer Community Forums.
Thank you, |