-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Query Execution
-
ALL
-
-
None
-
3
-
TBD
-
None
-
None
-
None
-
None
-
None
-
None
-
None
If you try to project "sortKey" metadata when it does not exist, the query will fail correctly like:
assert.commandWorked(coll.insertMany([ {_id: 0, x: "hi"}, ])); let query2 = [ {$project: {metaField: {$meta: "sortKey"}}}, ]; assert.commandFailedWithCode( coll.getDB().runCommand({aggregate: coll.getName(), pipeline: query2, cursor: {}}), ErrorCodes.BadValue);
However, if you put a $project exclusion before the same projection of the "sortKey" metadata, the query will start passing (incorrectly) like:
let query1 = [ {$project: {x: 0}}, {$project: {metaField: {$meta: "sortKey"}}}, ]; assert.commandFailedWithCode( coll.getDB().runCommand({aggregate: coll.getName(), pipeline: query1, cursor: {}}), ErrorCodes.BadValue);
This seems specific to "sortKey" metadata, as other metadata types like "geoNearDistance", "textScore", and "searchScore" fail correctly in the second case (I didn't try every metadata possibility).
Note, its possible this is related to SERVER-107874 as these both show this difference in behavior when the query involves a $project exclusion first in the query that does not fail correctly. They may be different however, its unclear to me.
- is related to
-
SERVER-107874 $project exclusion followed by $project exclusion inclusion mix stops tracking metadata correctly
-
- Needs Scheduling
-