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

$lookup with an array of sub objects should allow for an option to allow each sub object to find join partners

    XMLWordPrintable

    Details

      Description

      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"
                }
          }
      

      Expected Output

          {
              x:/.../,
              a:[{
                  _b:[Object],
                  c:/.../,
                  _d:/.../,
                  e:{
                      f:/.../
                  }
              }]
          }
      

      Output

          {
              x:/.../,
              a: {
       
                  _b: [Object]
       
              }
          }
      

       

       

      As you can see above, fields inside the "a" gets overwritten by the $lookup operation, and the field called "a" turns into an object after the aggregation (just like in the behavior of the $unwind operator).

       

       

       

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              backlog-server-query Backlog - Query Team
              Reporter:
              mertanilhasret@hotmail.com Mert Hasret
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

                Dates

                Created:
                Updated: