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 } } }
- duplicates
-
SERVER-6527 in projection implementation, dotted field inclusion supersedes parent field inclusion
-
- Closed
-