Details
-
Bug
-
Resolution: Unresolved
-
Unknown
-
None
-
2.22.0
-
None
-
None
Description
Summary
ReplaceWith, ReplaceRoot & Project pipeline stages don't seem to respect the serializer's configuration when using a new expression of a customized class map.
How to Reproduce
Run the following unit test
public class ReplaceWithBug |
{
|
[Fact]
|
public void ReplaceWithShouldRenderElementNameCorrectly() |
{
|
BsonClassMap.RegisterClassMap<User>(cm =>
|
{
|
cm.AutoMap();
|
cm.MapMember(c => c.UserId).SetElementName("uuid"); |
});
|
|
|
var client = new MongoClient(new MongoClientSettings { LinqProvider = MongoDB.Driver.Linq.LinqProvider.V3 }); |
var collection = client.GetDatabase("db").GetCollection<User>("user"); |
|
|
var rendered = PipelineStageDefinitionBuilder |
.ReplaceWith<User, User>(u => new User { UserId = u.UserId }) |
.Render(collection.DocumentSerializer, collection.Settings.SerializerRegistry, collection.Database.Client.Settings.LinqProvider);
|
|
|
var bson = rendered.Document.ToString(); |
|
|
Assert.Equal("""{ "$replaceWith" : { "uuid" : "$uuid" } }""", bson); |
}
|
}
|
|
|
public class User |
{
|
public Guid UserId { get; set; } |
}
|
Running the unit test produces the following error:
Message:
|
Assert.Equal() Failure: Strings differ
|
↓ (pos 22)
|
Expected: "{ "$replaceWith" : { "uuid" : "$uuid" } }"
|
Actual: ···""$replaceWith" : { "UserId" : "$uuid" } }"
|
↑ (pos 22)
|
Attachments
Issue Links
- is related to
-
CSHARP-4555 Linq3 projection stage generated by group does not use registered class maps
-
- Backlog
-
-
CSHARP-4579 Pipeline projection translator does not use registered BsonClassMap and throws exception
-
- Closed
-