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

Null Reference Exception using Unwind with a Projection

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor - P4
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0
    • Component/s: API
    • Labels:
      None

      Description

      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();
      

        Attachments

          Activity

            People

            Assignee:
            craiggwilson Craig Wilson
            Reporter:
            craiggwilson Craig Wilson
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: