Details
-
Bug
-
Resolution: Done
-
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
,
g => new Root
);
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
}
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