|
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,
|
...
|
|