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

Aggregation lookup array field return no results

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 4.0.9
    • Component/s: Aggregation Framework
    • Labels:
      None
    • ALL
    • Hide

      001-rs:PRIMARY> db.users.insert({ emails: [

      { address: 'a@b.com' }

      ] })
      WriteResult({ "nInserted" : 1 })
      001-rs:PRIMARY> db.test.find()
      001-rs:PRIMARY> db.test.insert({ myArr: ['a@b.com'] })
      WriteResult({ "nInserted" : 1 })
      001-rs:PRIMARY> db.test.aggregate([{ $lookup: { from: 'users', let:

      { arr: '$myArr' }

      , pipeline: [{ $match: { $expr:

      { $in: ['$emails.address', '$$arr'] }

      } }], as: 'lookedUp' } }])

      { "_id" : ObjectId("5cc682c309168dd75e9cc67f"), "myArr" : [ "a@b.com" ], "lookedUp" : [ ] }
      Show
      001-rs:PRIMARY> db.users.insert({ emails: [ { address: 'a@b.com' } ] }) WriteResult({ "nInserted" : 1 }) 001-rs:PRIMARY> db.test.find() 001-rs:PRIMARY> db.test.insert({ myArr: ['a@b.com'] }) WriteResult({ "nInserted" : 1 }) 001-rs:PRIMARY> db.test.aggregate([{ $lookup: { from: 'users', let: { arr: '$myArr' } , pipeline: [{ $match: { $expr: { $in: ['$emails.address', '$$arr'] } } }], as: 'lookedUp' } }]) { "_id" : ObjectId("5cc682c309168dd75e9cc67f"), "myArr" : [ "a@b.com" ], "lookedUp" : [ ] }

      Linux yukinohito-Linux-Mint-18 4.15.0-47-generic #50~16.04.1-Ubuntu SMP Fri Mar 15 16:06:21 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

      I need to lookup array of emails to users, where user have email set following way:

      { emails: [ \{ address: 'a@b.com' }

      ] }

      But seems currently advanced $lookup in aggregation does not match it, always return 0 results in result field. Shouldn't it be working same way is in usual query?

            Assignee:
            eric.sedor@mongodb.com Eric Sedor
            Reporter:
            cherviakov.ivan@gmail.com Ivan Cherviakov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: