public bool DeleteOne <T>(string collectionName, string field, T value) { try { var filter = Builders.FilterEq <T>(field, value); var collection = _database.GetCollection <BsonDocument>(collectionName); collection.DeleteOne(filter); return(true); } catch { return(false); } }
public bool UpdateOne(string collectionName, string field, string value, UpdateDefinition <BsonDocument> update) { try { var filter = Builders.FilterEq(field, value); var collection = _database.GetCollection <BsonDocument>(collectionName); collection.UpdateOne(filter, update); return(true); } catch (Exception ex) { string xx = ex.Message; return(false); } }
public long SelectCount <T>(string collectionName, string field, T value) { var collection = _database.GetCollection <BsonDocument>(collectionName); return(collection.Find(Builders.FilterEq <T>(field, value)).CountDocuments()); }
public long SelectCount(string collectionName, string field, ObjectId id) { var collection = _database.GetCollection <BsonDocument>(collectionName); return(collection.Find(Builders.FilterEq(field, id)).CountDocuments()); }