private DeleteResult DeleteOne(FilterDefinition <TDocument> filter, DeleteOptions options, Func <IEnumerable <WriteModel <TDocument> >, BulkWriteOptions, BulkWriteResult> bulkWrite) { Ensure.IsNotNull(filter, nameof(filter)); options = options ?? new DeleteOptions(); var model = new DeleteOneModel <TDocument>(filter) { Collation = options.Collation, Hint = options.Hint }; try { var bulkWriteOptions = new BulkWriteOptions { Comment = options.Comment, Let = options.Let }; var result = bulkWrite(new[] { model }, bulkWriteOptions); return(DeleteResult.FromCore(result)); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }
private async Task <DeleteResult> DeleteOneAsync(FilterDefinition <TDocument> filter, DeleteOptions options, Func <IEnumerable <WriteModel <TDocument> >, BulkWriteOptions, Task <BulkWriteResult <TDocument> > > bulkWriteAsync) { Ensure.IsNotNull(filter, nameof(filter)); options = options ?? new DeleteOptions(); var model = new DeleteOneModel <TDocument>(filter) { Collation = options.Collation, Hint = options.Hint }; try { var bulkWriteOptions = new BulkWriteOptions { Comment = options.Comment, Let = options.Let }; var result = await bulkWriteAsync(new[] { model }, bulkWriteOptions).ConfigureAwait(false); return(DeleteResult.FromCore(result)); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }
public async Task <DeleteResult> DeleteOneAsync(DeleteOneModel <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 DeleteOne(FilterDefinition <TDocument> filter, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(filter, nameof(filter)); var model = new DeleteOneModel <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> DeleteOneAsync(FilterDefinition <TDocument> filter, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(filter, "filter"); var model = new DeleteOneModel <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); } }