MongoDb driver C# Filter editing

137 views Asked by At

Maybe it is a simple question, but I stack on it and cannot go ahead.

I need to make a query to MongoDb via C# driver. I can easily generate a complex filter by using FilterDefinition myFilter ...

new FilterDefinition<BsonDocument> myFilter = { "$and": [{ "D20": { "$in": [1654, 1659 ] } }, { "D22": 1666 }] }; //That is just sample, creating filter logic more complex

But when I need to edit it and remove some clause(for ex { "D22": 1666 }) from it, don't have any clue how to do this by using only FilterDefinition, without converting to json or string.

1

There are 1 answers

0
Marcolia On

Try this

var filter = Builders<BsonDocument>.Filter.Eq("name", value);
var update = Builders<BsonDocument>.Update.Set("Name", new value);
collection.UpdateOne(filter, update);