[CSHARP-1384] IAggregateFluent<T> ignores BsonElement attribute Created: 21/Aug/15  Updated: 13/Apr/16  Resolved: 05/Apr/16

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Kevin De Coninck [X] Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 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



 Comments   
Comment by Craig Wilson [ 24/Mar/16 ]

Hi Kevin,

Sorry for the late reply. We are ignoring these on purpose because (a) these names are completely temporary in the context of a query; no data is persisted and (b) we need to ignore them particulary related to type information since these are projected types.

Is this causing a problem for you? We could certainly opt-in to supporting just BsonElement for naming, but that seems like it doesn't really do anything except make your queries look different. No functionality is lost or enabled here.

Craig

Generated at Wed Feb 07 21:39:26 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.