[SERVER-56027] Relax a restriction on exclusion of a field in inclusion projection Created: 12/Apr/21  Updated: 27/Oct/23  Resolved: 22/Apr/21

Status: Closed
Project: Core Server
Component/s: Query Planning
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Ruslan Abdulkhalikov (Inactive) Assignee: Backlog - Query Optimization
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Optimization
Operating System: ALL
Participants:

 Description   

This restriction is counter-intuitive and makes little sense:

<field>:<0 or false> Specifies the exclusion of a field.
To exclude a field conditionally, use the REMOVE variable instead. For details, see Exclude Fields Conditionally.
If you specify the exclusion of a field other than _id, you cannot employ any other $project specification forms. This restriction does not apply to conditionally exclusion of a field using the REMOVE variable.
See also the $unset stage to exclude fields.

 

> db.sample2.aggregate([{$project: {i1:1, str1:0}}])
Error: command failed: {
	"ok" : 0,
	"errmsg" : "Invalid $project :: caused by :: Cannot do exclusion on field str1 in inclusion projection",
	"code" : 31254,
...

 


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