Accessing nested array variable in $lookup+$let+$expr seems undefined

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Works as Designed
    • Priority: Major - P3
    • None
    • Affects Version/s: 4.4.7, 6.0.3
    • Component/s: None
    • None
    • Query Execution
    • ALL
    • Hide

      Create collection "machine"  with data

      {"_id":"qqq","lines":[{"devices":{"type-c":{"disabled":false}}}]} 

      Create collection device with data

      {"machineId":"qqq","deviceEnabled":false}
      {"machineId":"qqq","deviceEnabled":false} 

      Execute aggregation

      db.machine.aggregate([    {
              $lookup: {
                  'from': 'device',
                  let: {mId: '$_id', m_device_disabled: "$lines.devices.type-c.disabled"},
                  as: 'res',
                  pipeline: [
                      {
                          $match:
                          {
                              $expr:
                              {
                                  $and:
                                      [
                                          { $eq: ['$$mId', '$machineId'] }
                                         ,{ $eq: [{$toBool: '$$m_device_disabled'},{$toBool: "$deviceEnabled"}] }
                                      ]
                              }
                          }
                      }]
              }
          }
          ,   {
               $project: {
                 'res.deviceEnabled': 1, 
                 'res._id': 1
                 ,'_id': 1
               }
           }
          ])
          
          

      Expected result:

      {
          "_id" : "qqq",
          "res" : [
              {
                  "_id" : ObjectId("6371fcc7ce3e296eed4c2b0c"),
                  "deviceEnabled" : false
              },
              {
                  "_id" : ObjectId("6371fcc7ce3e296eed4c2b32"),
                  "deviceEnabled" : false
              }
          ]
      } 

      Actual result:

      {
          "_id" : "qqq",
          "res" : [ ]
      } 
      Show
      Create collection "machine"  with data { "_id" : "qqq" , "lines" :[{ "devices" :{ "type-c" :{ "disabled" : false }}}]} Create collection device with data { "machineId" : "qqq" , "deviceEnabled" : false } { "machineId" : "qqq" , "deviceEnabled" : false } Execute aggregation db.machine.aggregate([    {         $lookup: {             'from' : 'device' ,             let: {mId: '$_id' , m_device_disabled: "$lines.devices.type-c.disabled" },             as: 'res' ,             pipeline: [                 {                     $match:                     {                         $expr:                         {                             $and:                                 [                                     { $eq: [ '$$mId' , '$machineId' ] }                                    ,{ $eq: [{$toBool: '$$m_device_disabled' },{$toBool: "$deviceEnabled" }] }                                 ]                         }                     }                 }]         }     }     ,   {          $project: {             'res.deviceEnabled' : 1,              'res._id' : 1            , '_id' : 1          }      }     ])          Expected result: {     "_id" : "qqq" ,     "res" : [         {             "_id" : ObjectId( "6371fcc7ce3e296eed4c2b0c" ),             "deviceEnabled" : false         },         {             "_id" : ObjectId( "6371fcc7ce3e296eed4c2b32" ),             "deviceEnabled" : false         }     ] } Actual result: {     "_id" : "qqq" ,     "res" : [ ] }
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      I'm trying to make a join of two colections by multiple fields, one of them is boolean and in case when this field is "false"

        1. test.device.json
          0.1 kB
          Igor Nem
        2. test.machine.json
          0.1 kB
          Igor Nem
        3. repro.js
          2 kB
          Edwin Zhou

            Assignee:
            [DO NOT USE] Backlog - Query Execution
            Reporter:
            Igor Nem
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: