/// <summary>
        /// 根据ID列表 物理删除一组数据
        /// </summary>
        /// <returns></returns>
        public bool RemoveByTypeIdList(IEnumerable <ObjectId> ids)
        {
            var filter = Builders <T> .Filter.AnyIn("_id", ids);

            try
            {
                DeleteResult result = MongoCollection.DeleteManyAsync(filter).Result;
                if (result.DeletedCount != ids.Count())
                {
                    // 没有完全删除,做日志记录
                    MongoLog.Logger.Warning($"根据ID列表 物理删除一组数据 ==> 已删除数据:{result.DeletedCount}条,按条件应删除{ids.Count()}条\r\n 类型:[{typeof(T).FullName}]\r\n查询条件为:[{ids.ToJson()}] ");
                    return(false);
                }
                return(true);
            }
            catch (System.TimeoutException te)
            {
                MongoLog.Logger.Warning(te, "数据库链接超时。链接字符串:" + Provider.Connection.ConnectionString());
                throw;
            }
            catch (Exception ex)
            {
                MongoLog.Logger.Warning(ex, "操作异常终止。");
                throw;
            }
        }
 /// <summary>
 ///  将对象内容作为查询条件来物理删除数据
 /// </summary>
 /// <param name="entity"></param>
 public void RemoveSearch(T entity)
 {
     MongoLog.Logger.Debug($"物理删除数据 ==> 类型:[{typeof(T).FullName}]\r\n数据信息为:[{entity.ToJson()}] ");
     try
     {
         var          query  = MongoSerializer.SerializeQueryModel(entity);
         DeleteResult result = MongoCollection.DeleteManyAsync(query).Result;
         if (result.DeletedCount == 0)
         {
             MongoLog.Logger.Debug($"将对象内容作为查询条件来物理删除数据 ==> 无数据被删除。\r\n 类型:[{typeof(T).FullName}]\r\n查询条件为:[{entity.ToJson()}] ");
             return;
         }
         MongoLog.Logger.Debug($"将对象内容作为查询条件来物理删除数据 ==> 已删除数据:{result.DeletedCount}条\r\n 类型:[{typeof(T).FullName}]\r\n查询条件为:[{entity.ToJson()}] ");
     }
     catch (System.TimeoutException te)
     {
         MongoLog.Logger.Warning(te, "数据库链接超时。链接字符串:" + Provider.Connection.ConnectionString());
         throw;
     }
     catch (Exception ex)
     {
         MongoLog.Logger.Warning(ex, "操作异常终止。");
         throw;
     }
 }
Exemplo n.º 3
0
        public async Task <int> Delete(IWorkContext context, FilterDefinition <TDocument> filter)
        {
            Verify.IsNotNull(nameof(context), context);
            Verify.IsNotNull(nameof(filter), filter);

            var options = new DeleteOptions();

            DeleteResult deleteResult = await MongoCollection.DeleteManyAsync(filter, options, context.CancellationToken);

            return((int)deleteResult.DeletedCount);
        }
Exemplo n.º 4
0
 public async Task DeleteManyAsync(Filter filter, CancellationToken cancellationToken = default(CancellationToken))
 {
     var deleteFilter = _ConvertToFilterDefinition(filter);
     await MongoCollection.DeleteManyAsync(deleteFilter, cancellationToken);
 }
Exemplo n.º 5
0
 public async Task DeleteAsync(IEnumerable <T> obj)
 {
     await MongoCollection.DeleteManyAsync(Builders <T> .Filter.In(x => x.Id, obj.Select(x => x.Id)));
 }
Exemplo n.º 6
0
 public async Task DeleteAsync(Expression <Func <T, bool> > p)
 {
     await MongoCollection.DeleteManyAsync(p);
 }
Exemplo n.º 7
0
 public static async void DeleteAsync(IEnumerable <T> obj)
 {
     await MongoCollection.DeleteManyAsync(Builders <T> .Filter.In(x => x._id, obj.Select(x => x._id)));
 }
 public Task Delete(Expression <Func <T, bool> > where)
 {
     return(MongoCollection.DeleteManyAsync(where));
 }