Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

279
Views
C# MongoDB UpdateManyAsync with Set method throws an exception

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; }
    }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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; }
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!