C# MongoDB UpdateManyAsync with Set 方法抛出异常
C# MongoDB UpdateManyAsync with Set method throws an exception
我使用 c# mongodb 驱动程序。当我想更新我的特定值时,它会抛出异常。我以前用过这个,但我现在不知道如何使用,但我之前没有收到任何错误。这是我的代码:
var result = await col.UpdateManyAsync(
p => p.X > 5,
Builders<Payment>.Filter.Gt(p => p.Amount, 100).Set("Level", "High")
);
这是我的付款 class:
public class Payment
{
public ObjectId Id { get; set; }
public decimal Amount { get; set; }
public Type Type { get; set; }
}
您的付款 class 中没有等级 属性。如果这正是您想要做的,那么您需要将 BsonIgnoreExtraElements 属性添加到您的付款 class 否则它会抛出如下错误:
[BsonIgnoreExtraElements]
public class Payment
{
public ObjectId Id { get; set; }
public decimal Amount { get; set; }
public Type Type { get; set; }
}
我使用 c# mongodb 驱动程序。当我想更新我的特定值时,它会抛出异常。我以前用过这个,但我现在不知道如何使用,但我之前没有收到任何错误。这是我的代码:
var result = await col.UpdateManyAsync(
p => p.X > 5,
Builders<Payment>.Filter.Gt(p => p.Amount, 100).Set("Level", "High")
);
这是我的付款 class:
public class Payment
{
public ObjectId Id { get; set; }
public decimal Amount { get; set; }
public Type Type { get; set; }
}
您的付款 class 中没有等级 属性。如果这正是您想要做的,那么您需要将 BsonIgnoreExtraElements 属性添加到您的付款 class 否则它会抛出如下错误:
[BsonIgnoreExtraElements]
public class Payment
{
public ObjectId Id { get; set; }
public decimal Amount { get; set; }
public Type Type { get; set; }
}