[CSHARP-1705] IQueryable - Join operation fails following previous filter and join Created: 12/Jul/16 Updated: 31/Aug/18 Resolved: 31/Aug/18 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Linq |
| Affects Version/s: | 2.2.4 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Andrew Bennett | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows 7 |
||
| Attachments: |
|
| Description |
|
When using the Join operation on an IQueryable the operation throws an exception in the following circumstances 1. Join one typed collection's items to another on an integer field; Queryable of Item A to Queryable Item B On the call to toArray() the following exception is thrown:
Please see attached code for full reproduction |
| Comments |
| Comment by Craig Wilson [ 19/Aug/16 ] | |||||||||||||||||||||||||||||||||||||||
|
Hi Andrew, Sorry about the wait. I missed your comment. So, I chased down the wrong issue with your query. Your answer is much simpler. I've changed your code to the following:
As commented in the code, MongoDB's $lookup stage can't join to another pipeline, only to another collection. So, in this case, (and because this is an inner join), we can reverse the inner and outer entities. This generates the below pipeline, for those interested:
The title of this ticket is actually correct. We cannot join to something that has a previous anything, be it a filter, join, select, etc... This is a MongoDB limitation and there is nothing we can do about it. Just to note, MongoDB 3.4 will be supporting readonly views, which are defined as a pipeline. From .NET, you'd use them like a collection. This might allow you to get around the $lookup restriction. Hope that helps, and my apologies for mis-diagnosing this initially. | |||||||||||||||||||||||||||||||||||||||
| Comment by Andrew Bennett [ 05/Aug/16 ] | |||||||||||||||||||||||||||||||||||||||
|
Hi Craig, Thanks for looking into this for us. Any chance you could modify my reproduction to demonstrate this working? I think we tried this ourselves and had issues but it would be really clear if you could upload our reproduction corrected to project anonymous types. Thanks | |||||||||||||||||||||||||||||||||||||||
| Comment by Craig Wilson [ 05/Aug/16 ] | |||||||||||||||||||||||||||||||||||||||
|
Hi Andrew, So, I'm able to do n-ary joins without an issue. I believe the ultimate problem with your example is that you are projecting entire entities. For instance, you join Product to Order and then your result select is the Product. Unfortunately, there is no good way to handle this in MongoDB 3.2. For now, you'll need to project into an anonymous type or a new entity or something. For instance, simply projecting new {product, order}would be sufficient. In MongoDB 3.4, this will be possible by using an exclusion projection. However, until then, we can't really do anything substantial. I'm going to move this ticket to driver release 2.4 with a dependency on the 3.4 server. Craig | |||||||||||||||||||||||||||||||||||||||
| Comment by Andrew Bennett [ 15/Jul/16 ] | |||||||||||||||||||||||||||||||||||||||
|
Hi any idea when this issue will be looked into? This and C-SHARP-1702 are critical to a bug we need to fix. Thanks |