-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.5.1
-
Component/s: Builders
-
None
-
Environment:Windows 10, Visual Studio 2017
When using the aggregation framework sorting after an unwinding step fails with the following exception:
System.ArgumentException HResult=0x80070057 Message=The input type to stage[1] was expected to be MongoDB.Bson.BsonDocument, but was MongoIssue.TestModel_Unwound. Parametername: stages Source=MongoDB.Driver StackTrace: at MongoDB.Driver.PipelineStagePipelineDefinition`2.VerifyStages(List`1 stages) at MongoDB.Driver.PipelineStagePipelineDefinition`2..ctor(IEnumerable`1 stages, IBsonSerializer`1 outputSerializer) at MongoDB.Driver.AggregateFluent`2.ThenBy(SortDefinition`1 newSort) at MongoDB.Driver.IAggregateFluentExtensions.ThenBy[TResult](IOrderedAggregateFluent`1 aggregate, Expression`1 field) at MongoIssue.Program.Main(String[] args) in C:\Users\fals\source\repos\MongoIssue\MongoIssue\Program.cs:line 33
The snippet that throws the exception is:
var query = collection.Aggregate()
.Unwind(x => x.Items)
.As<TestModel_Unwound>()
.SortBy(sortExpression1)
.ThenBy(sortExpression2);
A small project reproducing the issue is attached.