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

Aggregation, sorting after unwinding fails

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.5.1
    • Component/s: Builders
    • None
    • Environment:
      Windows 10, Visual Studio 2017
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      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:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: