[SERVER-55595] Matching results with empty path component don't make sense Created: 29/Mar/21  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Query Language
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Mathias Stearn Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Optimization
Operating System: ALL
Participants:
Case:

 Description   

> db.foo.find({'x.': 1})
{ "_id" : ObjectId("6061e7ac7cc9a947848c1015"), "x" : [ 1 ], "y" : [ { "" : 1 } ] }
{ "_id" : ObjectId("6061e7f27cc9a947848c1016"), "x" : { "" : [ 1 ] }, "y" : [ { "" : 1 } ] }
> db.foo.find({'y.': 1})
>

If we aren't going to error when there is an empty path component, the results should at least make sense. I can't think of any reason (modulo bugs of course) why the first document would match {'x.': 1}. And the second document should either match both or neither of {'x.': 1} and {'y.': 1}. The current behavior where it matches one but not the other is odd.



 Comments   
Comment by Mathias Stearn [ 29/Mar/21 ]

Note that we already error if you use an empty path in the projection, so errorring out when they are in the match predicate also seems reasonable.

> db.foo.find({}, {'x.': 1})
Error: error: {
        "ok" : 0,
        "errmsg" : "FieldPath must not end with a '.'.",
        "code" : 40353,
        "codeName" : "Location40353"
}
> db.foo.find({}, {'x..1': 1})
Error: error: {
        "ok" : 0,
        "errmsg" : "FieldPath field names may not be empty strings.",
        "code" : 15998,
        "codeName" : "Location15998"
}
> db.foo.find({'x..y': 1})
>

Generated at Thu Feb 08 05:36:54 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.