C# 當數據項被刪除修改後,MongoDb無法反序列化數據,報錯類似"does not match any field or property of class"
解決方案就是告訴MongoDb在反序列化時忽略那些數據結構沒有的數據項目
https://stackoverflow.com/questions/23448634/mongodb-c-sharp-driver-ignore-fields-on-binding/45307268
[BsonIgnoreExtraElements]
public class UserModel
{
public ObjectId id { get; set; }
public string Email { get; set; }
}
或者
BsonClassMap.RegisterClassMap<UserModel>(cm =>
{
cm.AutoMap();
cm.SetIgnoreExtraElements(true);
});