I use c# mongodb driver. When I want to update my specific values, it throws an exception. I used this before but I don't now how but i didn't get any error before. Here's my code:
var result = await col.UpdateManyAsync(
p => p.X > 5,
Builders<Payment>.Filter.Gt(p => p.Amount, 100).Set("Level", "High")
);
And here's my Payment class:
public class Payment
{
public ObjectId Id { get; set; }
public decimal Amount { get; set; }
public Type Type { get; set; }
}
You don't have Level property in your Payment class. If this is exactly what you want to do, then you need to add BsonIgnoreExtraElements attribute to your Payment class otherwise it throws an error as follows:
[BsonIgnoreExtraElements]
public class Payment
{
public ObjectId Id { get; set; }
public decimal Amount { get; set; }
public Type Type { get; set; }
}