/// <summary> /// Delete an item from the collection /// </summary> /// <param name="item"></param> public void Delete(T item) { if (typeof(T).IsSubclassOf(typeof(BaseMongoId))) { BaseMongoId id = item as BaseMongoId; collection.DeleteOne(new BsonDocument("_id", ObjectId.Parse(id.Id))); } }
/// <summary> /// Saves data to the database /// </summary> /// <param name="item"></param> public void Save(T item) { if (typeof(T).IsSubclassOf(typeof(BaseMongoId))) { BaseMongoId id = item as BaseMongoId; if (id.Id == null) { collection.InsertOne(item); } else { collection.ReplaceOne(new BsonDocument("_id", ObjectId.Parse(id.Id)), item, new UpdateOptions { IsUpsert = true }); } } else { collection.InsertOne(item); } }
/// <summary> /// Delete an item from the collection /// </summary> /// <param name="item"></param> public void Delete(BaseMongoId item) { collection.DeleteOne(new BsonDocument("_id", ObjectId.Parse(item.Id))); }