private async Task <DeleteResult> DeleteManyAsync(FilterDefinition <TDocument> filter, DeleteOptions options, Func <IEnumerable <WriteModel <TDocument> >, BulkWriteOptions, Task <BulkWriteResult <TDocument> > > bulkWriteFuncAsync) { Ensure.IsNotNull(filter, nameof(filter)); options = options ?? new DeleteOptions(); var model = new DeleteManyModel <TDocument>(filter) { Collation = options.Collation, Hint = options.Hint }; try { var bulkWriteOptions = new BulkWriteOptions { Let = options.Let }; var result = await bulkWriteFuncAsync(new[] { model }, bulkWriteOptions).ConfigureAwait(false); return(DeleteResult.FromCore(result)); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }
private DeleteResult DeleteMany(FilterDefinition <TDocument> filter, DeleteOptions options, Func <IEnumerable <WriteModel <TDocument> >, BulkWriteOptions, BulkWriteResult> bulkWriteFunc) { Ensure.IsNotNull(filter, nameof(filter)); options = options ?? new DeleteOptions(); var model = new DeleteManyModel <TDocument>(filter) { Collation = options.Collation, Hint = options.Hint }; try { var bulkWriteOptions = new BulkWriteOptions { Comment = options.Comment, Let = options.Let }; var result = bulkWriteFunc(new[] { model }, bulkWriteOptions); return(DeleteResult.FromCore(result)); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }
public async Task <DeleteResult> DeleteManyAsync(DeleteManyModel <TDocument> model, TimeSpan?timeout, CancellationToken cancellationToken) { Ensure.IsNotNull(model, "model"); try { var bulkModel = new BulkWriteModel <TDocument>(new[] { model }); var result = await BulkWriteAsync(bulkModel, timeout, cancellationToken); return(DeleteResult.FromCore(result)); } catch (BulkWriteException <TDocument> ex) { throw WriteException.FromBulkWriteException(ex); } }
/// <inheritdoc /> public virtual DeleteResult DeleteMany(FilterDefinition <TDocument> filter, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(filter, nameof(filter)); var model = new DeleteManyModel <TDocument>(filter); try { var result = BulkWrite(new[] { model }, null, cancellationToken); return(DeleteResult.FromCore(result)); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }
/// <inheritdoc /> public virtual async Task <DeleteResult> DeleteManyAsync(FilterDefinition <TDocument> filter, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(filter, "filter"); var model = new DeleteManyModel <TDocument>(filter); try { var result = await BulkWriteAsync(new[] { model }, null, cancellationToken).ConfigureAwait(false); return(DeleteResult.FromCore(result)); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }