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

$lookup overwrites the entire object and erases fields (other than what "as" holds) when used inside an array of nested objects

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • ALL
    • Hide
      • Create a schema as shown in the "Description" section. 
      • Run the query given in the "Description" section on one of the versions listed in "Affects Version/s" section.
      • PS: My assumption is that the given aggregation doesn't give the expected output past 3.4.5, but I have only listed the version that I have tested the aggregation on.
      Show
      Create a schema as shown in the "Description" section.  Run the query given in the "Description" section on one of the versions listed in "Affects Version/s" section. PS: My assumption is that the given aggregation doesn't give the expected output past 3.4.5, but I have only listed the version that I have tested the aggregation on.

      Schema:
      {
      x:

      {type: String, required: true}

      ,
      a: [{
      _b:

      {type: Schema.Types.ObjectId, ref: "B", required: true}

      ,
      c:

      {type: Number, required: true}

      ,
      _d:

      {type: Schema.Types.ObjectId, ref: "D", required: true}

      ,
      e: {
      f:

      {type: Number, required: true}

      }
      }]
      }

      lookup stage:
      {
      "$lookup":

      { from: "B", localField: "a._b", foreignField: "_id", as: "a._b" }

      },
      {
      "$unwind":

      { path: "$a._b" }

      }

      expected result:
      {
      x:/.../,
      a:{
      _b:[Object],
      c:/.../,
      _d:/.../,
      e:

      { f:/.../ }

      }
      }

      result:
      {
      x:/.../,
      a:

      { _b: [Object] }

      ,
      }

      As you can see above, fields inside the "a" gets overwritten by the $lookup operation.

            Assignee:
            Unassigned Unassigned
            Reporter:
            mertanilhasret@hotmail.com Mert Hasret
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: