-
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 run a query like:
assert.commandWorked(coll.insertMany([ {_id: 0, x: "hi", y: "bye"}, ])); let onlyInclusion = [ {$project: {x: 0}}, {$project: {y: 1, metaField: {$meta: "textScore"}}}, ]; assert.commandFailedWithCode( coll.getDB().runCommand({aggregate: coll.getName(), pipeline: onlyInclusion, cursor: {}}), 40218);
This query will correctly fail, saying the "textScore" metadata is not available.
However if you flip the second $project to exclude with regular field while including the "textScore" metadata, the query will now pass (incorrectly):
let exclusionAndInclusion = [ {$project: {x: 0}}, {$project: {y: 0, metaField: {$meta: "textScore"}}}, ]; assert.commandFailedWithCode( coll.getDB().runCommand( {aggregate: coll.getName(), pipeline: exclusionAndInclusion, cursor: {}}), 40218);
I'm aware in the $project documentation that it states if you exclude fields, you should also not also include other fields , however, if you remove the first $project exclusion stage from the second query, it will start failing correctly. So, regardless, there is some inconsistency here that should be addressed.
Note, its possible this is related to SERVER-107875 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.
- related to
-
SERVER-107875 $project exclusion followed by $project inclusion of "sortKey" metadata does not fail correctly
-
- Needs Scheduling
-