IAggregateFluent<T> ignores BsonElement attribute

XMLWordPrintableJSON

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

      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

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

              Created:
              Updated:
              Resolved: