18
18
using FluentAssertions ;
19
19
using MongoDB . Bson ;
20
20
using MongoDB . Bson . Serialization ;
21
+ using MongoDB . Bson . TestHelpers ;
21
22
using MongoDB . Driver . Linq ;
22
23
using MongoDB . Driver . Linq . Linq3Implementation ;
23
24
using MongoDB . Driver . Linq . Linq3Implementation . Translators . ExpressionToExecutableQueryTranslators ;
@@ -33,18 +34,12 @@ public static void AssertStages(IEnumerable<BsonDocument> stages, IEnumerable<st
33
34
34
35
public static List < BsonDocument > Translate < TDocument , TResult > ( IMongoCollection < TDocument > collection , IAggregateFluent < TResult > aggregate )
35
36
{
36
- var renderedStages = new List < BsonDocument > ( ) ;
37
-
38
- IBsonSerializer inputSerializer = collection . DocumentSerializer ;
37
+ var pipelineDefinition = ( ( AggregateFluent < TDocument , TResult > ) aggregate ) . Pipeline ;
38
+ var documentSerializer = collection . DocumentSerializer ;
39
39
var serializerRegistry = BsonSerializer . SerializerRegistry ;
40
- foreach ( var stage in aggregate . Stages )
41
- {
42
- var renderedStage = stage . Render ( inputSerializer , serializerRegistry , LinqProvider . V3 ) ;
43
- renderedStages . Add ( renderedStage . Document ) ;
44
- inputSerializer = renderedStage . OutputSerializer ;
45
- }
46
-
47
- return renderedStages ;
40
+ var linqProvider = collection . Database . Client . Settings . LinqProvider ;
41
+ var renderedPipeline = pipelineDefinition . Render ( documentSerializer , serializerRegistry , linqProvider ) ;
42
+ return renderedPipeline . Documents . ToList ( ) ;
48
43
}
49
44
50
45
// in this overload the collection argument is used only to infer the TDocument type
0 commit comments