[SERVER-8585] null and {$exists: false} queries inside arrays match less than I'd expect Created: 14/Feb/13  Updated: 21/May/13  Resolved: 28/Feb/13

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

Type: Bug Priority: Major - P3
Reporter: David Glasser Assignee: Aaron Staple
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Tested with 2.2.1 on MacOS X.


Operating System: ALL
Participants:

 Description   

If I understand properly, the general rule for doing a query

{'a.x': QUERY}

where 'a' is an array is that it should match if there is any element of the 'a' array where

{x: QUERY}

matches.

But Mongo 2.2.1 does this:

> db.x.remove({}); db.x.insert({a: [

{x: 1}

, {}]})
> db.x.findOne({'a.x': {$exists: false}})
null
> db.x.findOne(

{'a.x': null}

)
null

That surprises me: I'd expect both of these to match, because there is an element of the 'a' array (the {}) such that both {x: {$exists: false}} and

{x: null}

matches.

I don't see any relevant tests in the jstests directory asserting that the current behavior is expected. Is this behavior intentional or a bug?



 Comments   
Comment by David Glasser [ 21/May/13 ]

My reading of the changes made for SERVER-6400 is that `

{'a.x': null}

` now does what I expect (and the arrayfind5.js test has been changed), but `{'a.x': {$exists: false}}` does not.

Comment by Aaron Staple [ 28/Feb/13 ]

David - I'm going to close this ticket, but feel free to reopen if you have further questions.

Comment by Aaron Staple [ 18/Feb/13 ]

It looks like one place this is tested is jstests/arrayfind5.js

Comment by Aaron Staple [ 18/Feb/13 ]

I believe this is "works as designed" per SERVER-3377.

There is some more discussion in the description of SERVER-5065 in the section on "Query Matching Semantics".

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