Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#MongoDB updatemanayasync with Set方法引发异常_C#_Mongodb_Mongodb .net Driver - Fatal编程技术网

C#MongoDB updatemanayasync with Set方法引发异常

C#MongoDB updatemanayasync with Set方法引发异常,c#,mongodb,mongodb-.net-driver,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") ); 付款类中没有级别属性。如果这正是您

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

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

付款类中没有级别属性。如果这正是您想要做的,那么您需要将BsonIgnoreExtraElements属性添加到您的Payment类中,否则它会引发如下错误:

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

噢我忘了。谢谢,成功了。是的,我正想这样做。如果大于100,我将添加一个属性。@s即使您的问题已解决,您也可以将此答案标记为解决方案:)啊,对不起,我不知道。我现在试过了,但它说你们必须等10分钟才能接受答案。也许是因为我是新来的:)
[BsonIgnoreExtraElements]
public class Payment
{
    public ObjectId Id { get; set; }
    public decimal Amount { get; set; }
    public Type Type { get; set; }
}