Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-56027

Relax a restriction on exclusion of a field in inclusion projection

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: Query Planning
    • Labels:
      None
    • Query Optimization
    • ALL

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

       

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            ruslan.abdulkhalikov@mongodb.com Ruslan Abdulkhalikov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: