diff --git a/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs b/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs index 443d8f89d3..45629f76e5 100644 --- a/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs +++ b/framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs @@ -507,11 +507,21 @@ public class MongoDbRepository var dbContext = await GetDbContextAsync(cancellationToken); var collection = dbContext.Collection(); - await collection.DeleteManyAsync( - dbContext.SessionHandle, - Builders.Filter.Where(predicate), - cancellationToken: cancellationToken - ); + if (dbContext.SessionHandle != null) + { + await collection.DeleteManyAsync( + dbContext.SessionHandle, + Builders.Filter.Where(predicate), + cancellationToken: cancellationToken + ); + } + else + { + await collection.DeleteManyAsync( + Builders.Filter.Where(predicate), + cancellationToken: cancellationToken + ); + } } [Obsolete("Use GetQueryableAsync method.")]