using MongoDB.Bson;
using MongoDB.Driver;
static MongoClient client = new MongoClient("mongodb://localhost:27017"); //Set the connection
string
static IMongoDatabase db =
client.GetDatabase("test"); //Database
name
public void DeleteOne(string id)
{
IMongoCollection<BsonDocument> collection =
db.GetCollection<BsonDocument>("user"); //table name
var filter = Builders<BsonDocument>.Filter.Eq("_id", BsonObjectId.Parse(id)); //Need to parse else you will get the error
var
res = collection.Find(filter).ToList();
collection.DeleteOne(filter);
}
No comments:
Post a Comment