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);
            }
        }
 public virtual Task <ReplaceOneResult> ReplaceOneAsync(IClientSessionHandle session, FilterDefinition <TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(ReplaceOneAsync(filter, replacement, ReplaceOptions.From(options), (requests, bulkWriteOptions) => BulkWriteAsync(session, requests, bulkWriteOptions, cancellationToken)));
 }
 /// <inheritdoc />
 public ReplaceOneResult ReplaceOne(IClientSessionHandle session, FilterDefinition <TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(ReplaceOne(filter, replacement, options, (requests, bulkWriteOptions) => BulkWrite(session, requests, bulkWriteOptions, cancellationToken)));
 }
 /// <inheritdoc />
 public Task <ReplaceOneResult> ReplaceOneAsync(FilterDefinition <TDocument> filter, TDocument replacement, ReplaceOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(ReplaceOneAsync(filter, replacement, options, (requests, bulkWriteOptions) => BulkWriteAsync(requests, bulkWriteOptions, cancellationToken)));
 }
 public virtual ReplaceOneResult ReplaceOne(FilterDefinition <TDocument> filter, TDocument replacement, UpdateOptions options, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(ReplaceOne(filter, replacement, ReplaceOptions.From(options), (requests, bulkWriteOptions) => BulkWrite(requests, bulkWriteOptions, cancellationToken)));
 }