[CSHARP-2539] _t Discriminator is lost when using ReplaceOneAsync Created: 06/Mar/19  Updated: 31/Mar/22

Status: Backlog
Project: C# Driver
Component/s: Serialization
Affects Version/s: 2.7.3
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Martin Schneider Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Visual Studio 2017, C#



 Description   

I am using the following generic code to replace a document with an updated version

 public async Task UpdateAsync<T>(T model, string collectionName) {
 var filter = Builders<T>.Filter.Eq("_id", model.Id);
 await database.GetCollection<T>(collectionName).ReplaceOneAsync(filter, model);
}

The documents are stored with a _t discriminator like that:

{ "_id" : "5c7fb949d0c890000179bb46", "_t" : "Type",  ....

After using ReplaceOneAsync the _t discriminator is removed from the file in the database.
I guess a workaround would be to manually cast model as the specific type and update all fields, which would result in _t not getting modified. (The question is if that is less performing.)


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