[SERVER-55739] Incorrect filter result when using a null match inside an indexed array field Created: 02/Apr/21 Updated: 02/Apr/21 Resolved: 02/Apr/21 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | None |
| Affects Version/s: | 4.4.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Giacomo Gregoletto | Assignee: | Eric Sedor |
| 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: | Create the following document inside a random collection:
Run this query:
The document will be returned by the database. The next query works as expected (no match):
|
||||||||
| Participants: | |||||||||
| Description |
|
MongoDB v4.4.4 (Atlas).
The database will match more documents than expected when using a null match against an array's item.
Tested with Compass, Robo3T, Mongo shell, and Node.js driver. |
| Comments |
| Comment by Giacomo Gregoletto [ 02/Apr/21 ] |
|
Ok, really interesting to hear this. Thank you for the fast response. |
| Comment by Eric Sedor [ 02/Apr/21 ] |
|
Hi giacomo.gregoletto@evologi.it; Thanks for writing. This unexpected behavior is the result of SERVER-27442, which discusses the known ambiguity of MQL for querying array elements vs. nested documents with keys that are also numbers. In short, the document matches "array.0.value":null because: But $type avoids this ambiguity because it explicitly filters on the BSON type for existing fields, as opposed to the "is null or doesn't exist" criteria of just querying for being equal to null. I'm going to close this ticket as a duplicate of SERVER-27442. Can you comment there if you have any questions about the issue? Gratefully, |