[SERVER-23286] Document field is empty when a subkey is after the parent key in projection Created: 22/Mar/16  Updated: 06/Dec/22  Resolved: 01/Apr/16

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

Type: Bug Priority: Minor - P4
Reporter: Mateusz Grabowski Assignee: Backlog - Query Team (Inactive)
Resolution: Duplicate Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-6527 in projection implementation, dotted ... Closed
Assigned Teams:
Query
Operating System: ALL
Steps To Reproduce:

Initiate test collection

db.test.insert({'contact': {'phone': {'number': 7}}})
db.test.insert({'contact': {'phone': {'extension': 42}}}

Query test collection

db.test.find({}, {'contact.phone': 1, 'contact.phone.extension': 1})
db.test.find({}, {'contact.phone': 1, 'contact.phone.extension': 1})

Participants:

 Description   

I generate projection parameters for my mongo queries, depends on a user choice.
I've noticed an unexpected behavior when I try getting some field (contact.phone) and subfield of the same field (contact.phone.extension). Content of the results depends on the order of projection.
The bug occours when a subkey is after the parent key in projection. The data under the parent key is missing.

Query A

> db.test.find({}, {'contact.phone': 1, 'contact.phone.extension': 1})
{ "_id" : ObjectId("56f157913e5215b0b37b1dfd"), "contact" : { "phone" : { "extension" : 42 } } }
{ "_id" : ObjectId("56f157b33e5215b0b37b1dfe"), "contact" : { "phone" : {  } } }

Query B

db.test.find({}, {'contact.phone.extension': 1, 'contact.phone': 1})
{ "_id" : ObjectId("56f157913e5215b0b37b1dfd"), "contact" : { "phone" : { "extension" : 42 } } }
{ "_id" : ObjectId("56f157b33e5215b0b37b1dfe"), "contact" : { "phone" : { "number" : 7 } } }



 Comments   
Comment by Ian Whalen (Inactive) [ 01/Apr/16 ]

Thanks for the report. We've confirmed that this is a dupe of SERVER-6527.

Comment by Ramon Fernandez Marina [ 28/Mar/16 ]

Thanks for the concise reproducer grabekm90, I'm able to reproduce this behavior and we're investigating.

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