[CSHARP-4818] LINQ GroupJoin Does Not Support $lookup with array of values Created: 24/Oct/23 Updated: 15/Nov/23 Resolved: 15/Nov/23 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | M. Scott Ford | Assignee: | Robert Stam |
| Resolution: | Gone away | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
SummaryThe `$lookup` aggregation pipeline step supports referencing a local field that contains an array of items. The `GroupJoin` method does not support this scenario, instead requiring that the local field is a single value. Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).
This applies to version 2.22.0. How to ReproduceSteps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example.
Given the following sample collections:
I can write the following aggregation pipeline:
And retrieve a result that looks like:
Using LINQ, I would expect to be able to do the following:
Additional BackgroundPlease provide any additional background information that may be helpful in diagnosing the bug. |
| Comments |
| Comment by PM Bot [ 15/Nov/23 ] | |||||||||||||||||||||||||||||||||||||||
|
There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to reopen this ticket if you're still experiencing the issue, and add a comment if you're able to provide more information. | |||||||||||||||||||||||||||||||||||||||
| Comment by PM Bot [ 07/Nov/23 ] | |||||||||||||||||||||||||||||||||||||||
|
Hi scott@freshli.io! If this is still an issue for you, please open Jira to review the latest status and provide your feedback. Thanks! | |||||||||||||||||||||||||||||||||||||||
| Comment by Robert Stam [ 30/Oct/23 ] | |||||||||||||||||||||||||||||||||||||||
|
The reason you are getting a compile time error is that LINQ requires a scalar expression for the ` outerKeySelector` argument to `GroupJoin`, and `x.Organizations` is an enumerable value. I don't think it's possible to do what you are trying to do directly in LINQ because of this. However, you could use LINQ to unwind the `Organizations` property and do a regular `Join` and then use `GroupBy` to populate the `Organizations` property of the final `Person` result. The following worked for me:
I needed the following intermediate classes as well:
| |||||||||||||||||||||||||||||||||||||||
| Comment by PM Bot [ 24/Oct/23 ] | |||||||||||||||||||||||||||||||||||||||
|
Hi scott@freshli.io, thank you for reporting this issue! The team will look into it and get back to you soon. |