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

Invalid query created when using unwind stage and match stage in Aggregate method

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.1
    • Component/s: None
    • None
    • Environment:
      WIndows 10 x64 FR
      Visual Studio 2015, .NET 4.5.2

      Driver has been compiled from the latest source in github (git master (49ecd1630d2aa4e634e86e4dc88731ae4f77f400))

      When using the Aggregate method like this:

      var aggregate = collection.Aggregate()
                      .Match(p => p.Id == entityId)
                      .Unwind<Entity, SubEntity>(p => p.SubEntities)
                      .OfType<SubEntityA>()
                      .Match(s => s.A == aValue);
      
                  aggregate = aggregate.SortBy(i => i.A);
                  var cursor = await aggregate.ToCursorAsync().ConfigureAwait(false);
      

      the generated query isn't correct. The output is:

      [{ "$match" : { "_id" : "1" } }, 
      { "$unwind" : "$SubEntities" }, 
      { "$match" : { "_t" : "SubEntityA" } }, 
      { "$match" : { "A" : "A12" } }, { "$sort" : { "A" : 1 } }]
      

      but should be:

      [{ "$match" : { "_id" : "1" } }, 
      { "$unwind" : "$SubEntities" }, 
      { "$match" : { "SubEntities._t" : "SubEntityA" } }, 
      { "$match" : { "SubEntities.A" : "A12" } }, 
      { "$sort" : { "SubEntities.A" : 1 } }]
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            phenixdotnet Vincent Lainé
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: