/// <inheritdoc />
        public virtual async Task <UpdateResult> UpdateManyAsync(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)
            {
                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 <UpdateResult> UpdateManyAsync(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 UpdateManyModel <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);
            }
        }
Example #3
0
        /// <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)
            {
                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);
            }
        }
Example #4
0
        public async Task <UpdateResult> UpdateManyAsync(UpdateManyModel <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(UpdateResult.FromCore(result));
            }
            catch (BulkWriteException <TDocument> ex)
            {
                throw WriteException.FromBulkWriteException(ex);
            }
        }
Example #5
0
        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);
            }
        }