[SERVER-6527] in projection implementation, dotted field inclusion supersedes parent field inclusion Created: 19/Jul/12  Updated: 09/Mar/20  Resolved: 16/Nov/19

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 2.0.6, 2.6.3
Fix Version/s: 4.3.2

Type: Bug Priority: Major - P3
Reporter: Aaron Staple Assignee: Ian Boros
Resolution: Done Votes: 1
Labels: query-44-grooming
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
Documented
is documented by DOCS-13322 Investigate changes in SERVER-6527: i... Closed
Duplicate
is duplicated by SERVER-6434 Query projection behavior shouldn't d... Closed
is duplicated by SERVER-39963 order of find projection with field a... Closed
is duplicated by SERVER-23286 Document field is empty when a subkey... Closed
is duplicated by SERVER-46670 Document the behavior when projection... Closed
Backwards Compatibility: Minor Change
Operating System: ALL
Sprint: Query 2019-11-04, Query 2019-11-18, Query 2019-12-02
Participants:

 Description   

Observed behavior: In the query projection implementation, the projection

{ a:1, 'a.b':1 }

is equivalent to

{ 'a.b':1 }

not

{ a:1 }

(at least in some cases).
Expected behavior: The projection

{ a:1, 'a.b':1 }

is equivalent to

{ a:1 }

.

Test:

> c.save( { a:[ 1, { b:2 }, { c:3 } ] } )
> c.find( {}, { a:1 } )
{ "_id" : ObjectId("50085e465d040dc2ab6a269a"), "a" : [ 1, { "b" : 2 }, { "c" : 3 } ] }
> c.find( {}, { 'a.b':1 } )
{ "_id" : ObjectId("50085e465d040dc2ab6a269a"), "a" : [ { "b" : 2 }, { } ] }
> c.find( {}, { a:1, 'a.b':1 } )
{ "_id" : ObjectId("50085e465d040dc2ab6a269a"), "a" : [ { "b" : 2 }, { } ] }



 Comments   
Comment by Githook User [ 15/Nov/19 ]

Author:

{'username': 'puppyofkosh', 'email': 'ian.boros@mongodb.com', 'name': 'Ian Boros'}

Message: SERVER-6527 test that projections with conflicting fields are banned
Branch: master
https://github.com/mongodb/mongo/commit/533ea624ef55bd30f5b9c697f9dcbc6b474ba239

Comment by Asya Kamsky [ 09/Oct/17 ]

Same in 3.5.13 - when there are multiple projections for same field, the last one wins (so 'a.b':1 followed by a:1 is equivalent to just a:1).

Comment by Thomas Rueckstiess [ 29/Jul/14 ]

Confirmed in 2.6.3.

Comment by Aaron Staple [ 25/Aug/12 ]

Also

> c.drop()
true
> c.save( { a:1 } )
> c.find( {}, { a:0, 'a.b':0 } )
{ "_id" : ObjectId("50384ea8eea50e9570278a48"), "a" : 1 }

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