Hello, I am here to understand if I am doing something wrong or it’s the standard beheviour.
I have a Document on the database defined with the class
public class Document {
public string Name { get; set; }
public string Description{ get; set; }
public List<string> Children { get; set; }
}
The properties on MongoDb are traslated by the following global rules
ConventionRegistry.Register("camelCase", new ConventionPack {
new CamelCaseElementNameConvention()
}, _ => true);
So all the properties is camelCase on the Db
Here is the ProjectClass
public class ProjectionDocument {
[BsonElement("name")]
public string Name { get; set; }
[BsonElement("description")]
public string Description { get; set; }
}
This projectionClass is also registered as:
BsonClassMap.RegisterClassMap<ProjectionDocument>(cm =>
{
cm.AutoMap();
});
When I read the data I am doing the follow:
IMongoCollection<Document>().Aggregate()
.Match(matchDefinition)
.Project(a => new ProjectionDocument {
Name = a.Name,
Description = a.Description,
}
.Group(a => a.Name, a => new ProjectionDocument {
Name = a.Key,
Description = a.First().Description,
}
.Sort(Builders<ProjectionDocument>.Sort.Ascending("name"))
.ToList();
This does not sorting right.
If I use “Name” instead of “name” it will work.
It is the expected behaviour ?
I am not using a Lamba expression because the sort field definition can be anything.
Second question:
Is
Project(Builders<Document>.Projection.Expression(a => new ProjectionDocument { ... }))
the same things as
.Project(a => new ProjectionDocument { ... })
?
Thanks in advance.
Kind Regards