[SERVER-40876] Aggregation lookup array field return no results Created: 29/Apr/19 Updated: 07/Apr/23 Resolved: 30/Apr/19 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Aggregation Framework |
| Affects Version/s: | 4.0.9 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | Ivan Cherviakov | Assignee: | Eric Sedor |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Operating System: | ALL |
| Steps To Reproduce: | 001-rs:PRIMARY> db.users.insert({ emails: [ { address: 'a@b.com' }] }) , pipeline: [{ $match: { $expr: { $in: ['$emails.address', '$$arr'] }} }], as: 'lookedUp' } }]) { "_id" : ObjectId("5cc682c309168dd75e9cc67f"), "myArr" : [ "a@b.com" ], "lookedUp" : [ ] } |
| Participants: |
| Description |
|
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? |
| Comments |
| Comment by Eric Sedor [ 30/Apr/19 ] |
|
Understood; thank you! |
| Comment by Ivan Cherviakov [ 30/Apr/19 ] |
|
Hi Eric Sedor. That is correct. I was confused first that initial aggregation not working but then I think again how $in compare values and understood the way to resolve it - add $unwind before. So this is totally resolved and there is no bug in mongodb same as there no need to any additional feature here. |
| Comment by Eric Sedor [ 29/Apr/19 ] |
|
Hi IvanCherviakov; do we understand correctly from your last comment that you are no longer reporting a potential bug or feature request? If we've misunderstood, can you clarify? |
| Comment by Ivan Cherviakov [ 29/Apr/19 ] |
|
On the second thought it shouldn't actually working like in non-aggregation case and we just need to unwind result from target collection: 001-rs:PRIMARY> db.test.aggregate([{ $lookup: { from: 'users', let: { arr: '$myArr' }, pipeline: [{ $unwind: '$emails' }, { $match: { $expr: { $in: ['$emails.address', '$$arr'] } } }], as: 'lookedUp' } }]) } ] } |