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

    • Query Optimization

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

       

       

       

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            mertanilhasret@hotmail.com Mert Hasret
            Votes:
            4 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated: