[CSHARP-1486] Support $$ROOT in LINQ for agg Created: 23/Nov/15  Updated: 02/Nov/21  Resolved: 02/Nov/21

Status: Closed
Project: C# Driver
Component/s: Linq
Affects Version/s: 2.1.1
Fix Version/s: 2.14.0

Type: Bug Priority: Major - P3
Reporter: Carlos Casanova Assignee: Robert Stam
Resolution: Done Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows, C#, MongoDB 3.0.7


Issue Links:
Depends
depends on CSHARP-3933 Support AggregateFluent.Group with ex... Closed
Related

 Description   

The expected behavior of GroupBy method on LINQ is to return a IGrouping<TKey,TDocument>, where TKey is the group key type and TDocument is a IEnumerable<TDocument>. In this case it returns an empty IEnumerable.

Is this the expected behavior? Becasue this in not the expected in other LINQ implementations.



 Comments   
Comment by Robert Stam [ 02/Nov/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

var connectionString = "mongodb://localhost";
var clientSettings = MongoClientSettings.FromConnectionString(connectionString);
clientSettings.LinqProvider = LinqProvider.V3;
var client = new MongoClient(clientSettings);

Comment by Githook User [ 02/Nov/21 ]

Author:

{'name': 'rstam', 'email': 'robert@robertstam.org', 'username': 'rstam'}

Message: CSHARP-1486: Verify that GroupBy works with $$ROOT in LINQ3.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/540636d26c312bb224f7d94f63bb037a99a9f8db

Comment by Craig Wilson [ 24/Nov/15 ]

I'm sorry. I was apparently unclear. We need to do this inside the driver. There is not a way for you to do this right now.

Craig

Comment by Carlos Casanova [ 23/Nov/15 ]

That's good to know, but I couldn't find a way to use $$ROOT from LINQ. Is there any place in the documentation that explains this?

Comment by Craig Wilson [ 23/Nov/15 ]

This is currently expected behavior. MongoDB sort of supports this behavior using the special $$ROOT global variable. Also If you continue on in the LINQ query and create some aggregates, it will work with those. I'll leave this ticket open as an improvement to support this using $$ROOT.

Generated at Wed Feb 07 21:39:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.