[CSHARP-4061] LINQ3 AggregateFluent.ToString() will not render GroupStageDefinition Created: 16/Feb/22  Updated: 28/Oct/23  Resolved: 25/Feb/22

Status: Closed
Project: C# Driver
Component/s: LINQ3
Affects Version/s: None
Fix Version/s: 2.15.0

Type: Bug Priority: Minor - P4
Reporter: Rich Collette Assignee: Robert Stam
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: CSHARP-3615

 Description   

Summary

Even with LINQ3 configured, and with a working aggregate that contains a Group method, when calling AggregateFluent.ToString() while debugging, I get an InvalidOperationException with the message "GroupExpressStageDefinitions can only be used with LINQ3"

Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

How to Reproduce

Steps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example.

Additional Background

Please provide any additional background information that may be helpful in diagnosing the bug.

Stack trace.

_
 _at MongoDB.Driver.Linq.Linq3Implementation.GroupExpressionStageDefinitions`3.GroupStageDefinition.Render(IBsonSerializer`1 inputSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider)_
 _at MongoDB.Driver.AppendedStagePipelineDefinition`3.Render(IBsonSerializer`1 inputSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider)_
 _at MongoDB.Driver.AppendedStagePipelineDefinition`3.Render(IBsonSerializer`1 inputSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider)_
 _at MongoDB.Driver.AppendedStagePipelineDefinition`3.Render(IBsonSerializer`1 inputSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider)_
 _at MongoDB.Driver.AppendedStagePipelineDefinition`3.Render(IBsonSerializer`1 inputSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider)_
 _at MongoDB.Driver.PipelineDefinition`2.ToString(IBsonSerializer`1 inputSerializer, IBsonSerializerRegistry serializerRegistry, LinqProvider linqProvider)_
 _at MongoDB.Driver.PipelineDefinition`2.ToString(IBsonSerializer`1 inputSerializer, IBsonSerializerRegistry serializerRegistry)_
 _at MongoDB.Driver.PipelineDefinition`2.ToString()_
 _at System.Text.ValueStringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)_
 _at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)_
 _at System.String.Format(String format, Object arg0)_
 _at MongoDB.Driver.AggregateFluent`2.ToString()_
_



 Comments   
Comment by Githook User [ 25/Feb/22 ]

Author:

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

Message: CSHARP-4061: Use correct LinqProvider in AggregateFluent ToString.
Branch: master
https://github.com/mongodb/mongo-csharp-driver/commit/e37fd9210c5a617ead8a704c305eee9bfa5c941e

Comment by James Kovacs [ 16/Feb/22 ]

Thank you for reporting this issue. This is a known limitation of Fluent Aggregate at the moment, but only affects the ToString() method, not the rendered MQL sent to the server.

When ToString() is called on an AggregateFluent instance, we forward the ToString() call to the PipelineDefinition. At this point in the callstack we don't have easy access to which LINQ provider is configured for the MongoClient and assume that it is LINQ2 for backwards compatibility.

We plan to fix this issue in an upcoming release. Please monitor this ticket for updates.

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