[SERVER-14874] Querying on {$ne:null} on embedded documents within arrays inconsistent between 2.4 and 2.6 Created: 12/Aug/14  Updated: 10/Dec/14  Resolved: 13/Aug/14

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

Type: Bug Priority: Major - P3
Reporter: Norman Graham Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-12444 null equality matches on dotted queri... Closed
Related
is related to SERVER-14877 Matcher incorrect on null equality qu... Closed
Operating System: ALL
Steps To Reproduce:

db.test.insert({ "_id" : 1, "a" : [ { "b" : 2 }, { "b" : 3, "c" : { "d" : 4, "e" : 5 } } ] });
db.test.find({_id:1,"a.c.d":{$ne:null}});
db.test.find({_id:1,"a.c.d":{$exists:true}});
db.test.insert({ "_id" : 2, "a" : [ { "b" : 3, "c" : { "d" : 4, "e" : 5 } } ] });
db.test.find({_id:2,"a.c.d":{$ne:null}});
db.test.find({_id:2,"a.c.d":{$exists:true}});

Participants:

 Description   

Querying on {$ne:null} on embedded documents within arrays is inconsistent with behavior under 2.4.10. Documents that would normally be matched will fail to match in the presence of subdocuments in the array that do not match the query criteria.

Workaround is to use {$exists:true} instead.



 Comments   
Comment by Norman Graham [ 13/Aug/14 ]

@rassi, agreed, this looks like a duplicate of SERVER-12444. Noted in particular are the 2.6 compatibility changes on null equality changes on array elements documented in http://docs.mongodb.org/manual/release-notes/2.6-compatibility/#null-comparison-queries.

Free to close.

Comment by J Rassi [ 12/Aug/14 ]

Does the 2.6 behavior make sense to you if you think of {a: {$ne: <value>}} the same as {$nor: [{a: <value>}]}?

> db.version()
2.6.4
> db.test.find()
{ "_id" : 1, "a" : [  {  "b" : 2 },  {  "b" : 3,  "c" : {  "d" : 4,  "e" : 5 } } ] }
{ "_id" : 2, "a" : [  {  "b" : 3,  "c" : {  "d" : 4,  "e" : 5 } } ] }
> db.test.find({"a.c.d":null})
{ "_id" : 1, "a" : [  {  "b" : 2 },  {  "b" : 3,  "c" : {  "d" : 4,  "e" : 5 } } ] }
> db.test.find({"a.c.d":"a"})
> db.test.find({$nor:[{"a.c.d":null}]})
{ "_id" : 2, "a" : [  {  "b" : 3,  "c" : {  "d" : 4,  "e" : 5 } } ] }
> db.test.find({$nor:[{"a.c.d":"a"}]})
{ "_id" : 1, "a" : [  {  "b" : 2 },  {  "b" : 3,  "c" : {  "d" : 4,  "e" : 5 } } ] }
{ "_id" : 2, "a" : [  {  "b" : 3,  "c" : {  "d" : 4,  "e" : 5 } } ] }
> db.test.find({"a.c.d":{$ne:null}})
{ "_id" : 2, "a" : [  {  "b" : 3,  "c" : {  "d" : 4,  "e" : 5 } } ] }
> db.test.find({"a.c.d":{$ne:"a"}})
{ "_id" : 1, "a" : [  {  "b" : 2 },  {  "b" : 3,  "c" : {  "d" : 4,  "e" : 5 } } ] }
{ "_id" : 2, "a" : [  {  "b" : 3,  "c" : {  "d" : 4,  "e" : 5 } } ] }
>

Comment by J Rassi [ 12/Aug/14 ]

I believe this is a dup of SERVER-12444. norman.graham@10gen.com, do you agree?

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