Reputation: 4466
I am using mongodb driver in c#. I can create query for CRUD operations sqlserver in c# . But i need to Create query for mongodb and execute it . For an sample i attached Delete Delete Query
string query = string.Format("DELETE FROM {0} WHERE {1}"
ExecuteNonquery method i can execute it in sqlConnection
How i do this in mongodb?
Upvotes: 1
Views: 501
Reputation: 18845
You should see FilterDefinitionBuilder TDocument which provides a type-safe API for building up both simple and complex MongoDB queries.
For example to build up the filter { x: 10, y: { $lt: 20 } }
, you can use below:
var builder = Builders<BsonDocument>.Filter;
var filter = builder.Eq("x", 10) & builder.Lt("y", 20);
You can see more examples on mongo-csharp-driver tests for FilterDefinitionBuilder class.
Upvotes: 1