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

$lookup is not working in case of the localField is array

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.0-rc2
    • Component/s: Aggregation Framework
    • None
    • Environment:
      Windows7 64
    • Windows
    • Hide
      -----inventory--------
      /* 1 */
      {
          "_id" : 1,
          "sku" : "abc",
          "description" : "product 1",
          "instock" : 120
      }
      
      /* 3 */
      {
          "_id" : 3,
          "sku" : "ijk",
          "description" : "product 3",
          "instock" : 60
      }
      /* 5 */
      {
          "_id" : 5,
          "sku" : null,
          "description" : "Incomplete"
      }
      
      /* 6 */
      {
          "_id" : 6
      }
      ----Orders collection----
      /* 1 */
      {
          "_id" : 1,
          "item" : [ 
              {
                  "ID" : "abc"
              }, 
              {
                  "ID" : "jkl"
              }
          ],
          "price" : 12,
          "quantity" : 2
      }
      
      /* 2 */
      {
          "_id" : 2,
          "item" : [ 
              {
                  "ID" : "jkl"
              }
          ],
          "price" : 20,
          "quantity" : 1
      }
      
      /* 3 */
      {
          "_id" : 3
      }
      ----Aggregate function ---
      db.orders.aggregate([
          {
            $lookup:
              {
                from: "inventory",
                localField: "item.ID",
                foreignField: "sku",
                as: "inventory_docs"
              }    
         }
      ])
      
      Show
      -----inventory-------- /* 1 */ { "_id" : 1, "sku" : "abc", "description" : "product 1", "instock" : 120 } /* 3 */ { "_id" : 3, "sku" : "ijk", "description" : "product 3", "instock" : 60 } /* 5 */ { "_id" : 5, "sku" : null, "description" : "Incomplete" } /* 6 */ { "_id" : 6 } ----Orders collection---- /* 1 */ { "_id" : 1, "item" : [ { "ID" : "abc" }, { "ID" : "jkl" } ], "price" : 12, "quantity" : 2 } /* 2 */ { "_id" : 2, "item" : [ { "ID" : "jkl" } ], "price" : 20, "quantity" : 1 } /* 3 */ { "_id" : 3 } ----Aggregate function --- db.orders.aggregate([ { $lookup: { from: "inventory", localField: "item.ID", foreignField: "sku", as: "inventory_docs" } } ])

      When use $lookup to refer an array of keys to other collection. it give unexpected result.

            Assignee:
            charlie.swanson@mongodb.com Charlie Swanson
            Reporter:
            mahawas Mohamed Hawwas
            Votes:
            0 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              Resolved: