[CSHARP-2270] Aggregation, sorting after unwinding fails Created: 15/May/18  Updated: 31/Mar/22

Status: Backlog
Project: C# Driver
Component/s: Builders
Affects Version/s: 2.5.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Sascha Falk Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows 10, Visual Studio 2017


Attachments: Zip Archive MongoIssue.zip    

 Description   

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.


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