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

$lookup defined array variables

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.6.0, 3.6.4
    • Component/s: Aggregation Framework
    • Labels:
      None
    • ALL
    • Hide
      db.test.insert({ foo: [1, 2] })
      db.test.insert({ bar: 1 })
      
      db.test.aggregate([
          {
              $match: {
                  foo: 1
              }
          },
          {
              $lookup: {
                  from: 'test',
                  let: {
                      arr: '$foo'
                  },
                  pipeline: [
                      {
                          $match: {
                              bar: {
                                  $in: '$$arr'
                              }
                          }
                      }
                  ],
                  as: 'result'
              }
          }
      ])
      

      and it will throw:

      { 
          "operationTime" : Timestamp(1526389658, 1), 
          "ok" : 0.0, 
          "errmsg" : "$in needs an array", 
          "code" : NumberInt(2), 
          "codeName" : "BadValue", 
          "$clusterTime" : {
              "clusterTime" : Timestamp(1526389658, 1), 
              "signature" : {
                  "hash" : BinData(0, "AAAAAAAAAAAAAAAAAAAAAAAAAAA="), 
                  "keyId" : NumberLong(0)
              }
          }
      }
      

      but projection shows:

      db.test.aggregate([
          {
              $match: {
                  foo: 1
              }
          },
          {
              $lookup: {
                  from: 'test',
                  let: {
                      arr: '$foo'
                  },
                  pipeline: [
                      {
                          $match: {
                              bar:1
                          }
                      },
                      {
                          $project: {
                              arr: '$$arr'
                          }
                      }
                  ],
                  as: 'result'
              }
          }
      ])
      

      that $$arr is in fact an array:

      { 
          "_id" : ObjectId("5afad86a91c788853024d506"), 
          "foo" : [
              1.0, 
              2.0
          ], 
          "result" : [
              {
                  "_id" : ObjectId("5afadc2c91c788853024d507"), 
                  "arr" : [
                      1.0, 
                      2.0
                  ]
              }
          ]
      }
      
      Show
      db.test.insert({ foo: [1, 2] }) db.test.insert({ bar: 1 }) db.test.aggregate([ { $match: { foo: 1 } }, { $lookup: { from: 'test' , let: { arr: '$foo' }, pipeline: [ { $match: { bar: { $in: '$$arr' } } } ], as: 'result' } } ]) and it will throw: { "operationTime" : Timestamp(1526389658, 1), "ok" : 0.0, "errmsg" : "$in needs an array" , "code" : NumberInt(2), "codeName" : "BadValue" , "$clusterTime" : { "clusterTime" : Timestamp(1526389658, 1), "signature" : { "hash" : BinData(0, "AAAAAAAAAAAAAAAAAAAAAAAAAAA=" ), "keyId" : NumberLong(0) } } } but projection shows: db.test.aggregate([ { $match: { foo: 1 } }, { $lookup: { from: 'test' , let: { arr: '$foo' }, pipeline: [ { $match: { bar:1 } }, { $project: { arr: '$$arr' } } ], as: 'result' } } ]) that $$arr is in fact an array: { "_id" : ObjectId( "5afad86a91c788853024d506" ), "foo" : [ 1.0, 2.0 ], "result" : [ { "_id" : ObjectId( "5afadc2c91c788853024d507" ), "arr" : [ 1.0, 2.0 ] } ] }

      It seems that array expression operators they do not see the defined variables as arrays.

            Assignee:
            Unassigned Unassigned
            Reporter:
            aPoCoMiLogin Filip
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: