private ReplaceOneResult ReplaceOne(FilterDefinition <TDocument> filter, TDocument replacement, UpdateOptions options, Func <IEnumerable <WriteModel <TDocument> >, BulkWriteOptions, BulkWriteResult <TDocument> > bulkWrite) { Ensure.IsNotNull(filter, nameof(filter)); Ensure.IsNotNull((object)replacement, "replacement"); if (options?.ArrayFilters != null) { throw new ArgumentException("ArrayFilters cannot be used with ReplaceOne.", nameof(options)); } options = options ?? new UpdateOptions(); var model = new ReplaceOneModel <TDocument>(filter, replacement) { Collation = options.Collation, IsUpsert = options.IsUpsert }; try { var bulkWriteOptions = new BulkWriteOptions { BypassDocumentValidation = options.BypassDocumentValidation }; var result = bulkWrite(new[] { model }, bulkWriteOptions); return(ReplaceOneResult.FromCore(result)); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }
private async Task <UpdateResult> UpdateOneAsync(FilterDefinition <TDocument> filter, UpdateDefinition <TDocument> update, UpdateOptions options, Func <IEnumerable <WriteModel <TDocument> >, BulkWriteOptions, Task <BulkWriteResult <TDocument> > > bulkWriteAsync) { Ensure.IsNotNull(filter, nameof(filter)); Ensure.IsNotNull(update, nameof(update)); options = options ?? new UpdateOptions(); var model = new UpdateOneModel <TDocument>(filter, update) { ArrayFilters = options.ArrayFilters, Collation = options.Collation, Hint = options.Hint, IsUpsert = options.IsUpsert }; try { var bulkWriteOptions = new BulkWriteOptions { BypassDocumentValidation = options.BypassDocumentValidation }; var result = await bulkWriteAsync(new[] { model }, bulkWriteOptions).ConfigureAwait(false); return(UpdateResult.FromCore(result)); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }
/// <inheritdoc /> public virtual async Task <ReplaceOneResult> ReplaceOneAsync(FilterDefinition <TDocument> filter, TDocument replacement, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(filter, nameof(filter)); Ensure.IsNotNull((object)replacement, "replacement"); if (options?.ArrayFilters != null) { throw new ArgumentException("ArrayFilters cannot be used with ReplaceOne.", nameof(options)); } options = options ?? new UpdateOptions(); var model = new ReplaceOneModel <TDocument>(filter, replacement) { Collation = options.Collation, IsUpsert = options.IsUpsert }; try { var bulkWriteOptions = new BulkWriteOptions { BypassDocumentValidation = options.BypassDocumentValidation }; var result = await BulkWriteAsync(new[] { model }, bulkWriteOptions, cancellationToken).ConfigureAwait(false); return(ReplaceOneResult.FromCore(result)); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }
/// <inheritdoc /> public virtual UpdateResult UpdateMany(FilterDefinition <TDocument> filter, UpdateDefinition <TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(filter, nameof(filter)); Ensure.IsNotNull(update, nameof(update)); options = options ?? new UpdateOptions(); var model = new UpdateManyModel <TDocument>(filter, update) { Collation = options.Collation, IsUpsert = options.IsUpsert }; try { var bulkWriteOptions = new BulkWriteOptions { BypassDocumentValidation = options.BypassDocumentValidation }; var result = BulkWrite(new[] { model }, bulkWriteOptions, cancellationToken); return(UpdateResult.FromCore(result)); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }
private UpdateResult UpdateMany(FilterDefinition <TDocument> filter, UpdateDefinition <TDocument> update, UpdateOptions options, Func <IEnumerable <WriteModel <TDocument> >, BulkWriteOptions, BulkWriteResult <TDocument> > bulkWrite) { Ensure.IsNotNull(filter, nameof(filter)); Ensure.IsNotNull(update, nameof(update)); options = options ?? new UpdateOptions(); var model = new UpdateManyModel <TDocument>(filter, update) { ArrayFilters = options.ArrayFilters, Collation = options.Collation, Hint = options.Hint, IsUpsert = options.IsUpsert }; try { var bulkWriteOptions = new BulkWriteOptions { BypassDocumentValidation = options.BypassDocumentValidation, Let = options.Let }; var result = bulkWrite(new[] { model }, bulkWriteOptions); return(UpdateResult.FromCore(result)); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }
/// <inheritdoc /> public virtual async Task <UpdateResult> UpdateOneAsync(FilterDefinition <TDocument> filter, UpdateDefinition <TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(filter, nameof(filter)); Ensure.IsNotNull(update, nameof(update)); options = options ?? new UpdateOptions(); var model = new UpdateOneModel <TDocument>(filter, update) { ArrayFilters = options.ArrayFilters, Collation = options.Collation, IsUpsert = options.IsUpsert }; try { var bulkWriteOptions = new BulkWriteOptions { BypassDocumentValidation = options.BypassDocumentValidation }; var result = await BulkWriteAsync(new[] { model }, bulkWriteOptions, cancellationToken).ConfigureAwait(false); return(UpdateResult.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 { Let = options.Let }; var result = await bulkWriteAsync(new[] { model }, bulkWriteOptions).ConfigureAwait(false); return(DeleteResult.FromCore(result)); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }
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 { Let = options.Let }; var result = bulkWrite(new[] { model }, bulkWriteOptions); return(DeleteResult.FromCore(result)); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }
/// <inheritdoc /> public virtual ReplaceOneResult ReplaceOne(FilterDefinition <TDocument> filter, TDocument replacement, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(filter, nameof(filter)); Ensure.IsNotNull((object)replacement, "replacement"); options = options ?? new UpdateOptions(); var model = new ReplaceOneModel <TDocument>(filter, replacement) { Collation = options.Collation, IsUpsert = options.IsUpsert }; try { var bulkWriteOptions = new BulkWriteOptions { BypassDocumentValidation = options.BypassDocumentValidation }; var result = BulkWrite(new[] { model }, bulkWriteOptions, cancellationToken); return(ReplaceOneResult.FromCore(result)); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }
private async Task <ReplaceOneResult> ReplaceOneAsync(FilterDefinition <TDocument> filter, TDocument replacement, ReplaceOptions options, Func <IEnumerable <WriteModel <TDocument> >, BulkWriteOptions, Task <BulkWriteResult <TDocument> > > bulkWriteAsync) { Ensure.IsNotNull(filter, nameof(filter)); Ensure.IsNotNull((object)replacement, "replacement"); options = options ?? new ReplaceOptions(); var model = new ReplaceOneModel <TDocument>(filter, replacement) { Collation = options.Collation, Hint = options.Hint, IsUpsert = options.IsUpsert }; try { var bulkWriteOptions = new BulkWriteOptions { BypassDocumentValidation = options.BypassDocumentValidation }; var result = await bulkWriteAsync(new[] { model }, bulkWriteOptions).ConfigureAwait(false); return(ReplaceOneResult.FromCore(result)); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }
/// <inheritdoc /> public virtual async Task InsertOneAsync(TDocument document, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull((object)document, "document"); var model = new InsertOneModel <TDocument>(document); try { await BulkWriteAsync(new[] { model }, null, cancellationToken).ConfigureAwait(false); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.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> 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); } }
private void InsertOne(TDocument document, InsertOneOptions options, Action <IEnumerable <WriteModel <TDocument> >, BulkWriteOptions> bulkWrite) { Ensure.IsNotNull((object)document, "document"); var model = new InsertOneModel <TDocument>(document); try { var bulkWriteOptions = options == null ? null : new BulkWriteOptions { BypassDocumentValidation = options.BypassDocumentValidation }; bulkWrite(new[] { model }, bulkWriteOptions); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }
/// <inheritdoc /> public virtual async Task InsertOneAsync(TDocument document, InsertOneOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull((object)document, "document"); var model = new InsertOneModel <TDocument>(document); try { var bulkWriteOptions = options == null ? null : new BulkWriteOptions { BypassDocumentValidation = options.BypassDocumentValidation }; await BulkWriteAsync(new[] { model }, bulkWriteOptions, cancellationToken).ConfigureAwait(false); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }
private async Task InsertOneAsync(TDocument document, InsertOneOptions options, Func <IEnumerable <WriteModel <TDocument> >, BulkWriteOptions, Task> bulkWriteAsync) { Ensure.IsNotNull((object)document, "document"); var model = new InsertOneModel <TDocument>(document); try { var bulkWriteOptions = options == null ? null : new BulkWriteOptions { BypassDocumentValidation = options.BypassDocumentValidation }; await bulkWriteAsync(new[] { model }, bulkWriteOptions).ConfigureAwait(false); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }
/// <inheritdoc /> public virtual async Task <UpdateResult> UpdateOneAsync(FilterDefinition <TDocument> filter, UpdateDefinition <TDocument> update, UpdateOptions options = null, CancellationToken cancellationToken = default(CancellationToken)) { Ensure.IsNotNull(filter, "filter"); Ensure.IsNotNull(update, "update"); options = options ?? new UpdateOptions(); var model = new UpdateOneModel <TDocument>(filter, update) { IsUpsert = options.IsUpsert }; try { var result = await BulkWriteAsync(new[] { model }, null, cancellationToken).ConfigureAwait(false); return(UpdateResult.FromCore(result)); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }
public async Task <ReplaceOneResult> ReplaceOneAsync(object filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken) { Ensure.IsNotNull(filter, "filter"); Ensure.IsNotNull((object)replacement, "replacement"); options = options ?? new UpdateOptions(); var model = new ReplaceOneModel <TDocument>(filter, replacement) { IsUpsert = options.IsUpsert }; try { var result = await BulkWriteAsync(new[] { model }, null, cancellationToken).ConfigureAwait(false); return(ReplaceOneResult.FromCore(result)); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }
public async Task <UpdateResult> UpdateManyAsync(object filter, object update, UpdateOptions options, CancellationToken cancellationToken) { Ensure.IsNotNull(filter, "filter"); Ensure.IsNotNull(update, "update"); options = options ?? new UpdateOptions(); var model = new UpdateManyModel <TDocument>(filter, update) { IsUpsert = options.IsUpsert }; try { var result = await BulkWriteAsync(new[] { model }, null, cancellationToken).ConfigureAwait(false); return(UpdateResult.FromCore(result)); } catch (MongoBulkWriteException <TDocument> ex) { throw MongoWriteException.FromBulkWriteException(ex); } }