gpt4 book ai didi

C# MongoDB UpdateManyAsync with Set 方法抛出异常

转载 作者:可可西里 更新时间:2023-11-01 09:58:46 28 4
gpt4 key购买 nike

我使用 c# mongodb 驱动程序。当我想更新我的特定值时,它会抛出异常。我以前用过这个,但我现在不知道如何使用,但我之前没有收到任何错误。这是我的代码:

var result = await col.UpdateManyAsync(
p => p.X > 5,
Builders<Payment>.Filter.Gt(p => p.Amount, 100).Set("Level", "High")
);

这是我的支付类:

public class Payment
{
public ObjectId Id { get; set; }
public decimal Amount { get; set; }
public Type Type { get; set; }
}

最佳答案

您的 Payment 类中没有 Level 属性。如果这正是您想要做的,那么您需要将 BsonIgnoreExtraElements 属性添加到您的 Payment 类,否则它会抛出如下错误:

[BsonIgnoreExtraElements]
public class Payment
{
public ObjectId Id { get; set; }
public decimal Amount { get; set; }
public Type Type { get; set; }
}

关于C# MongoDB UpdateManyAsync with Set 方法抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41855795/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com