[CSHARP-2071] Using Linq Aggregation to project the root document Created: 23/Oct/17 Updated: 28/Oct/23 Resolved: 25/Oct/21 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Linq |
| Affects Version/s: | 2.4.4 |
| Fix Version/s: | 2.14.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Stephen Bond | Assignee: | Robert Stam |
| Resolution: | Fixed | Votes: | 6 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||
| Description |
|
Expected Behaviour Using the aggregation pipeline I can perform the following:
Example below:
Using Linq, I believe this would be represented using the following Linq query:
Actual Behaviour Returns the following error when executed: Stack trace:
|
| Comments |
| Comment by Richard Collette [ 29/Oct/21 ] | |||||||||||||||||||||||||||||||||||||||
|
Hopefully the new version will also address a related typing issue. At design time, the IGrouping<> is seen as an IEnumerable, but at runtime, it wan't an array constructor. To get things to compile and get to the point where the error mentioned in this ticket occurs, I have to add an unused constructor to my Group class like:
WhereAs I could have just done something simpler like
or
If the types were in alignment In the mean time, I fell back to using BsonDocument (As is frequently necessary)
| |||||||||||||||||||||||||||||||||||||||
| Comment by Robert Stam [ 25/Oct/21 ] | |||||||||||||||||||||||||||||||||||||||
|
This issue has been fixed in the new LINQ provider (known as LINQ3) which will be included in the upcoming 2.14 release. Configure your MongoClientSettings to use LinqProvider.V3 if you want to use this functionality. To configure a client to use the LINQ3 provider use code like the following
| |||||||||||||||||||||||||||||||||||||||
| Comment by Githook User [ 25/Oct/21 ] | |||||||||||||||||||||||||||||||||||||||
|
Author: {'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}Message: | |||||||||||||||||||||||||||||||||||||||
| Comment by Dmitry Lukyanov (Inactive) [ 20/Jan/21 ] | |||||||||||||||||||||||||||||||||||||||
|
Unfortunately, with the suggested changes we can generate unsupported queries in some cases. Since this logic is already covered by LINQ3, I think we can postpone working on $$ROOT until releasing it | |||||||||||||||||||||||||||||||||||||||
| Comment by James Kovacs [ 03/Dec/20 ] | |||||||||||||||||||||||||||||||||||||||
|
Thank you for expressing your interest in seeing this issue fixed. Although the PR looks straightforward, modifying LINQ AST parsing can often have unforeseen consequences - fixing some usages while breaking others - especially in our current implementation. We are currently working on a new LINQ translator to address shortcomings of our current LINQ implementation. We are prioritizing work on this new implementation over fixing unsupported use cases in the current one. We will take this use case into consideration for the new LINQ translator. | |||||||||||||||||||||||||||||||||||||||
| Comment by Kirill Rakhman [ 27/Nov/20 ] | |||||||||||||||||||||||||||||||||||||||
|
Just stumbled open this. Please fix, there's a PR open since 2018. | |||||||||||||||||||||||||||||||||||||||
| Comment by Shiya Kohn [ 20/Feb/20 ] | |||||||||||||||||||||||||||||||||||||||
|
Why is this issue this old and has not been handled, from my dive into the source code this looks like a fairly simple implementation. This is one of many known serialization/translation bugs, that the MongoDB .NET team has been neglecting. There seems to be little updates happening in the practical side of the code base, and it's kinda making hard to maintain a clean code base while using this driver | |||||||||||||||||||||||||||||||||||||||
| Comment by Marko Bini? [ 05/Apr/18 ] | |||||||||||||||||||||||||||||||||||||||
|
I've opened GitHub pull request #319, with a small change that helps resolve this. Please see my comments over there. | |||||||||||||||||||||||||||||||||||||||
| Comment by Marko Bini? [ 05/Apr/18 ] | |||||||||||||||||||||||||||||||||||||||
|
Here's a test that shows it failing (for AggregateGroupTranslatorTests):
| |||||||||||||||||||||||||||||||||||||||
| Comment by Stephen Bond [ 23/Oct/17 ] | |||||||||||||||||||||||||||||||||||||||
|
Sorry forgot to mention the Exception type is: NotSupportedException |