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

IAggregateFluent<T> ignores BsonElement attribute

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Minor - P4 Minor - P4
    • None
    • None
    • None
    • None

    Description

      When you create an aggregation using the fluent api, it seems that the BsonElement attribute on an element property is ignored.

      See the following fluent aggregation:

      var aggregation = Collection.Aggregate()
      .Group(key => new Key

      { Name = key.Name, }

      ,
      g => new Root

      { Id = g.Key, }

      );

      This generates the following aggregation command:

      aggregate([{ "$group" : { "_id" :

      { "Name" : "$name" }

      } }])

      Note the capital "N" on "Name".

      I'm grouping on a class of the Key, and here's the code for that class.

      public class Key
      {
      [BsonElement("name")]
      public string Name

      { get; set; }

      }

      I'm clearly mentioning "name" here, without any capital.
      The generated aggregation should therefore be:

      aggregate([{ "$group" : { "_id" :

      { "name" : "$name" }

      } }])

      A fix is required because for best practice, field names should not be long (because they are repeated over every document in the collection).
      But POCO classes in C# might have long a descriptive names.

      A field in C# can be named "ArticleNumber", while in mongo I would like to name it "artNr".

      Kind regards

      Attachments

        Activity

          People

            Unassigned Unassigned
            DeepFritz Kevin De Coninck [X]
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: