2 c# mongodb mongodb-.net-driver
我使用c#mongodb驱动程序。当我想更新我的特定值时,它将引发异常。我以前用过,但现在不知道如何使用,但是以前没有任何错误。这是我的代码:
var result = await col.UpdateManyAsync(
p => p.X > 5,
Builders<Payment>.Filter.Gt(p => p.Amount, 100).Set("Level", "High")
);
Run Code Online (Sandbox Code Playgroud)
这是我的付款课程:
public class Payment
{
public ObjectId Id { get; set; }
public decimal Amount { get; set; }
public Type Type { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
您的Payment类中没有Level属性。如果这正是您要执行的操作,则需要向您的Payment类添加BsonIgnoreExtraElements属性,否则它将引发如下错误:
[BsonIgnoreExtraElements]
public class Payment
{
public ObjectId Id { get; set; }
public decimal Amount { get; set; }
public Type Type { get; set; }
}
Run Code Online (Sandbox Code Playgroud)