Example #1
0
        public static async Task <T> Update <T>(this T item) where T : IMongoModel
        {
            var collection = MongoTools.GetCollection <T>();
            await collection.ReplaceOneAsync(a => a.Id == item.Id, item);

            return(item);
        }
Example #2
0
        public static T UpdateSync <T>(this T item) where T : IMongoModel
        {
            var collection = MongoTools.GetCollection <T>();

            collection.ReplaceOne(a => a.Id == item.Id, item);
            return(item);
        }
Example #3
0
        public static async Task <T> Insert <T>(this T item) where T : IMongoModel
        {
            var collection = MongoTools.GetCollection <T>();
            await collection.InsertOneAsync(item);

            return(item);
        }
Example #4
0
        public static T InsertSync <T>(this T item) where T : IMongoModel
        {
            var collection = MongoTools.GetCollection <T>();

            collection.InsertOne(item);
            return(item);
        }
Example #5
0
        public static T Update <T>(this T item) where T : IMongoModel
        {
            var collection = MongoTools.GetCollection <T>();

            collection.Save(item);
            return(item);
        }
Example #6
0
 public static async Task Delete <T>(this T item) where T : IMongoModel
 {
     var collection = MongoTools.GetCollection <T>();
     var oid        = item.Id;
     await collection.DeleteOneAsync(a => a.Id == oid);
 }
Example #7
0
 public static async Task Delete <T>(this string id) where T : IMongoModel
 {
     var collection = MongoTools.GetCollection <T>();
     var oid        = new ObjectId(id);
     await collection.DeleteOneAsync(a => a.Id == oid);
 }
Example #8
0
        public static void Delete <T>(this T item) where T : IMongoModel
        {
            var collection = MongoTools.GetCollection <T>();

            collection.Remove(Query.EQ("_id", item.Id));
        }
Example #9
0
        public static void Delete <T>(this string id) where T : IMongoModel
        {
            var collection = MongoTools.GetCollection <T>();

            collection.Remove(Query.EQ("_id", ObjectId.Parse(id)));
        }