Exemplo n.º 1
0
 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);
     }
 }
Exemplo n.º 2
0
 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);
     }
 }
Exemplo n.º 3
0
        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());
        }
Exemplo n.º 4
0
        public long SelectCount(string collectionName, string field, ObjectId id)
        {
            var collection = _database.GetCollection <BsonDocument>(collectionName);

            return(collection.Find(Builders.FilterEq(field, id)).CountDocuments());
        }