[SERVER-14770] warn when more than one array is used in a query with $ projection operator Created: 01/Aug/14  Updated: 02/Aug/14  Resolved: 02/Aug/14

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

Type: Improvement Priority: Major - P3
Reporter: William Cross Assignee: hari.khalsa@10gen.com
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-1013 positional $ operator field mismatch Closed
Participants:

 Description   

When you query for a value on each of two arrays, both with positional operators, the $ projection operator can get pretty confused but smoothly performs the wrong operation.

Steps to reproduce:

Perform the following operations in the shell:

db.foo.insert( { a : [5, 6, 7, 8], b : [ 11, 12, 13, 14] } )
db.foo.find( { a : 7, b : 11 }, { "a.$" : 1 , _id : 0 } 

Expected result:

{ "a" : 7 }

or an exception

Actual result :

{ "a" : 5 }

Related documentation:

The following doc tells me not to do exactly what I did: http://docs.mongodb.org/manual/reference/operator/projection/positional/#proj._S_

"Only one array field can appear in the query document; i.e. the following query is incorrect:" (then the example shows me exactly what I did), but this is clearly a case where either an exception should be thrown, or else the $ operator should be made smarter.



 Comments   
Comment by Scott Hernandez (Inactive) [ 02/Aug/14 ]

dup of SERVER-1013

Comment by Ramon Fernandez Marina [ 01/Aug/14 ]

According to the documentation, only one array can appear on the query document, so

db.foo.find( { a : 7, b : 11 }, { "a.$" : 1 , _id : 0 })

is incorrect if both a and b are arrays.

Comment by William Cross [ 01/Aug/14 ]

By the way, the following query happily throws an exception:

db.foo.find( { "a": 7 } , { "b.$": 1, _id: 0})

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