Details
-
Bug
-
Resolution: Unresolved
-
Minor - P4
-
None
-
2.7.3
-
None
-
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.)