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

Null Reference Exception using Unwind with a Projection

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.0
    • Affects Version/s: 2.0
    • Component/s: API
    • None

      Given this schema:

      > db.foo.find().pretty()
      {
              "_id" : 1,
              "bars" : [
                      {
                              "x" : 1,
                              "y" : 2
                      },
                      {
                              "x" : 2,
                              "y" : 3
                      },
                      {
                              "x" : 1,
                              "y" : 4
                      }
              ]
      }
      

      and these classes:

              private class Foo
              {
                  public int Id;
      
                  public List<Bars> Bars;
              }
      
              private class UnwoundFoo
              {
                  public int Id;
                  [BsonElement("Bars")]
                  public Bar Bar;
              }
      
              private class Bar
              {
                  [BsonElement("x")]
                  public int X;
                  [BsonElement("y")]
                  public int Y;
              }
      

      The following aggregation query results in a NRE:

          var list = await col.Aggregate()
                      .Unwind<Foo, UnwoundFoo>(x => x.Bars)
                      .Match(x => x.Bar.X == 1)
                      .Project(x => new { X = x.Bar.X, Y = x.Bar.Y })
                      .ToListAsync();
      

            Assignee:
            craig.wilson@mongodb.com Craig Wilson
            Reporter:
            craig.wilson@mongodb.com Craig Wilson
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: