Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-2270

Aggregation, sorting after unwinding fails

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.5.1
    • Component/s: Builders
    • Labels:
      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            sfalk Sascha Falk
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: