[SERVER-14877] Matcher incorrect on null equality query when using array index notation with embedded field Created: 13/Aug/14  Updated: 06/Dec/22  Resolved: 11/Mar/19

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.6.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: J Rassi Assignee: Backlog - Query Team (Inactive)
Resolution: Duplicate Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Duplicate
duplicates SERVER-27442 Positional path component in match la... Backlog
is duplicated by SERVER-39884 Query for null on a field in embedded... Closed
Related
related to SERVER-27442 Positional path component in match la... Backlog
related to SERVER-14874 Querying on {$ne:null} on embedded do... Closed
Assigned Teams:
Query
Operating System: ALL
Participants:

 Description   

Queries of the form {"a.0.b": null} incorrectly match documents where "a" is an array such that the first element is a subdocument with a non-null value for "b".

Regression since 2.4. Affects 2.6.0 through 2.6.4.

Example repro:

> db.version()
2.6.4
> db.test.drop()
true
> db.test.insert({a:[{b:1}]})
> db.test.find({"a.0.b":null}) // incorrect: document should not be returned
{ "_id" : ObjectId("53eab15e36fe6f6cc7dd5e68"), "a" : [  {  "b" : 1 } ] }
> db.test.ensureIndex({"a.0.b":1})
> db.test.find({"a.0.b":null}) // correct: document not returned (matcher bypassed)
>



 Comments   
Comment by David Storch [ 13/Mar/19 ]

I've investigated this issue, and provided a thorough explanation for the observed behavior in this comment on SERVER-27442. Let's hold any further discussion of this issue on SERVER-27442 rather than here.

Comment by Craig Homa [ 04/Mar/19 ]

Closed as a duplicate of SERVER-27442.

Comment by J Rassi [ 13/Aug/14 ]

Interestingly, note also that the document from the example above, {a:[{b:1}]}, does match the query {"a.0": null} in both 2.4 and 2.6. However, it does not get returned when indexed, in both versions:

> db.test.drop()
true
> db.test.insert({a:[{b:1}]})
> db.test.find({"a.0":null}) // document returned? but the first element of "a" is non-null...
{ "_id" : ObjectId("53eac83636fe6f6cc7dd5e7a"), "a" : [  {  "b" : 1 } ] }
> db.test.ensureIndex({"a.0":1})
> db.test.find({"a.0":null}) // and now document not returned...
>

That is (unlike the shell session from the description) the above shell session exhibits the same behavior between 2.4.10 and 2.6.4.

Generated at Thu Feb 08 03:36:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.