Ejemplo n.º 1
0
        /// <inheritdoc />
        public virtual async Task <ReplaceOneResult> ReplaceOneAsync(FilterDefinition <TDocument> filter, TDocument replacement, UpdateOptions options = null, CancellationToken cancellationToken = default(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);
            }
        }