[SERVER-39963] order of find projection with field and dotted field changes results Created: 05/Mar/19  Updated: 05/Mar/19  Resolved: 05/Mar/19

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

Type: Bug Priority: Major - P3
Reporter: Roee Nizan Assignee: Eric Sedor
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

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

Run this code using mongo shell on an empty server.

This has the same results on server versions 4.0.6 and 4.1.8.

db.test.insert({
    'foo': {
        'bar': 0,
        'baz': 1
    }
});
for (projection of [
    {_id: 0, foo: 1},
    {_id: 0, foo: 1, 'foo.bar': 1},
    {_id: 0, 'foo.bar': 1, foo: 1},
]) {
    printjson(db.test.findOne({}, projection));
}

Output:

MongoDB shell version v4.0.0
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.6
{ "foo" : { "bar" : 0, "baz" : 1 } }
{ "foo" : { "bar" : 0 } }
{ "foo" : { "bar" : 0, "baz" : 1 } }

 

Participants:

 Description   

When querying documents, the order of the keys in the projection object change the results when it contains both a key and its sub-key.

The reporter could not find documentation for this behavior, so it seems unintended.

The reporter would expect all these projections to be equal:

{foo: 1}
{foo: 1, 'foo.bar': 1}
{'foo.bar': 1, foo: 1}



 Comments   
Comment by Eric Sedor [ 05/Mar/19 ]

Thanks for your report allegroai; this issue is tracked in SERVER-6527. You can watch that ticket for updates.

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