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

Incorrect $unwind query when using SelectMany in subobjects

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 2.8.0
    • Affects Version/s: 2.5
    • Component/s: Linq
    • None

      For SelectMany in subobjects, driver generate wrong unwind query

      We have 2 objects:

      public class Mention
          {
              [BsonRepresentation(BsonType.ObjectId)]
              public string Id { get; set; }
             
              public RelatedData Related { get; set; }
          }
      
          public class RelatedData
          {
              public List<int> Players { get; set; }
              public List<int> Clubs { get; set; }
          }
      

      And we have query:

      _context.For<Mention>().AsQueryable()
                     .Where(...)
                     .SelectMany(x => x.Related.Players)
                     .ToList()
      

      For this query driver generate :

      {  "$match" : {  ....  }  },
      {  "$unwind" : "$Players" } <--- must be "$Related.Players"
      
      

            Assignee:
            dmitry.lukyanov@mongodb.com Dmitry Lukyanov (Inactive)
            Reporter:
            zoxexivo@gmail.com Ivan Artemov
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: