Beispiel #1
0
 /// <inheritdoc />
 public abstract Task <TProjection> FindOneAndUpdateAsync <TProjection>(FilterDefinition <TDocument> filter, UpdateDefinition <TDocument> update, FindOneAndUpdateOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken));
        /// <summary>
        /// Finds a single document and updates it atomically.
        /// </summary>
        /// <typeparam name="TDocument">The type of the document.</typeparam>
        /// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
        /// <param name="collection">The collection.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="update">The update.</param>
        /// <param name="options">The options.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// The returned document.
        /// </returns>
        public static Task <TProjection> FindOneAndUpdateAsync <TDocument, TProjection>(this IMongoCollection <TDocument> collection, Expression <Func <TDocument, bool> > filter, UpdateDefinition <TDocument> update, FindOneAndUpdateOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(collection, "collection");
            Ensure.IsNotNull(filter, "filter");

            return(collection.FindOneAndUpdateAsync(new ExpressionFilterDefinition <TDocument>(filter), update, options, cancellationToken));
        }
 /// <inheritdoc />
 public virtual TProjection FindOneAndUpdate <TProjection>(FilterDefinition <TDocument> filter, UpdateDefinition <TDocument> update, FindOneAndUpdateOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
        public override Task <TProjection> FindOneAndUpdateAsync <TProjection>(FilterDefinition <TDocument> filter, UpdateDefinition <TDocument> update, FindOneAndUpdateOptions <TDocument, TProjection> options, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(filter, "filter");
            Ensure.IsNotNull(update, "update");

            options = options ?? new FindOneAndUpdateOptions <TDocument, TProjection>();
            var projection         = options.Projection ?? new EntireDocumentProjectionDefinition <TDocument, TProjection>();
            var renderedProjection = projection.Render(_documentSerializer, _settings.SerializerRegistry);

            var operation = new FindOneAndUpdateOperation <TProjection>(
                _collectionNamespace,
                filter.Render(_documentSerializer, _settings.SerializerRegistry),
                update.Render(_documentSerializer, _settings.SerializerRegistry),
                new FindAndModifyValueDeserializer <TProjection>(renderedProjection.ProjectionSerializer),
                _messageEncoderSettings)
            {
                IsUpsert       = options.IsUpsert,
                MaxTime        = options.MaxTime,
                Projection     = renderedProjection.Document,
                ReturnDocument = options.ReturnDocument.ToCore(),
                Sort           = options.Sort == null ? null : options.Sort.Render(_documentSerializer, _settings.SerializerRegistry)
            };

            return(ExecuteWriteOperation(operation, cancellationToken));
        }
        /// <summary>
        /// Finds a single document and updates it atomically.
        /// </summary>
        /// <typeparam name="TDocument">The type of the document.</typeparam>
        /// <param name="collection">The collection.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="update">The update.</param>
        /// <param name="options">The options.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// The returned document.
        /// </returns>
        public static Task <TDocument> FindOneAndUpdateAsync <TDocument>(this IMongoCollection <TDocument> collection, FilterDefinition <TDocument> filter, UpdateDefinition <TDocument> update, FindOneAndUpdateOptions <TDocument, TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(collection, "collection");
            Ensure.IsNotNull(collection, "filter");

            return(collection.FindOneAndUpdateAsync <TDocument>(
                       filter,
                       update,
                       options,
                       cancellationToken));
        }
Beispiel #6
0
        public Task <TResult> FindOneAndUpdateAsync <TResult>(object filter, object update, FindOneAndUpdateOptions <TResult> options, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(filter, "filter");
            Ensure.IsNotNull(update, "update");

            options = options ?? new FindOneAndUpdateOptions <TResult>();
            var resultSerializer = ResolveResultSerializer(options.ResultSerializer);

            var operation = new FindOneAndUpdateOperation <TResult>(
                _collectionNamespace,
                ConvertFilterToBsonDocument(filter),
                ConvertToBsonDocument(update),
                new FindAndModifyValueDeserializer <TResult>(resultSerializer),
                _messageEncoderSettings)
            {
                IsUpsert       = options.IsUpsert,
                MaxTime        = options.MaxTime,
                Projection     = ConvertToBsonDocument(options.Projection),
                ReturnDocument = options.ReturnDocument.ToCore(),
                Sort           = ConvertToBsonDocument(options.Sort)
            };

            return(ExecuteWriteOperation(operation, cancellationToken));
        }
 /// <inheritdoc />
 public virtual Task <TProjection> FindOneAndUpdateAsync <TProjection>(IClientSessionHandle session, FilterDefinition <TDocument> filter, UpdateDefinition <TDocument> update, FindOneAndUpdateOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
Beispiel #8
0
 public override Task <TProjection> FindOneAndUpdateAsync <TProjection>(FilterDefinition <TDocument> filter, UpdateDefinition <TDocument> update, FindOneAndUpdateOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(_wrappedCollection.FindOneAndUpdateAsync(CombineFilters(filter), update, options, cancellationToken));
 }
Beispiel #9
0
 public Task <TDocument> FindOneAndUpdateAsync(object filter, object update, FindOneAndUpdateOptions <TDocument> options, CancellationToken cancellationToken)
 {
     return(FindOneAndUpdateAsync <TDocument>(filter, update, options, cancellationToken));
 }
 public override TProjection FindOneAndUpdate <TProjection>(IClientSessionHandle session, FilterDefinition <TDocument> filter, UpdateDefinition <TDocument> update, FindOneAndUpdateOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(_wrappedCollection.FindOneAndUpdate(session, CombineFilters(filter), update, options, cancellationToken));
 }
Beispiel #11
0
        /// <summary>
        /// Finds a single document and updates it atomically.
        /// </summary>
        /// <typeparam name="TDocument">The type of the document.</typeparam>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <param name="collection">The collection.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="update">The update.</param>
        /// <param name="options">The model.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// The result of the operation.
        /// </returns>
        public static Task <TResult> FindOneAndUpdateAsync <TDocument, TResult>(this IMongoCollection <TDocument> collection, Expression <Func <TDocument, bool> > filter, Func <UpdateBuilder <TDocument>, UpdateBuilder <TDocument> > update, FindOneAndUpdateOptions <TResult> options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(collection, "collection");
            Ensure.IsNotNull(filter, "filter");
            Ensure.IsNotNull(update, "update");

            var updateBuilder = new UpdateBuilder <TDocument>();
            var updateObj     = update(updateBuilder);

            return(collection.FindOneAndUpdateAsync(filter, updateObj, options, cancellationToken));
        }
Beispiel #12
0
        /// <summary>
        /// Finds a single document and updates it atomically.
        /// </summary>
        /// <typeparam name="TDocument">The type of the document.</typeparam>
        /// <typeparam name="TResult">The type of the result.</typeparam>
        /// <param name="collection">The collection.</param>
        /// <param name="filter">The filter.</param>
        /// <param name="update">The update.</param>
        /// <param name="options">The model.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// The result of the operation.
        /// </returns>
        public static Task <TResult> FindOneAndUpdateAsync <TDocument, TResult>(this IMongoCollection <TDocument> collection, Expression <Func <TDocument, bool> > filter, object update, FindOneAndUpdateOptions <TResult> options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(collection, "collection");
            Ensure.IsNotNull(filter, "filter");

            return(collection.FindOneAndUpdateAsync(filter, update, options, cancellationToken));
        }
        private FindOneAndUpdateOperation <TProjection> CreateFindOneAndUpdateOperation <TProjection>(FilterDefinition <TDocument> filter, UpdateDefinition <TDocument> update, FindOneAndUpdateOptions <TDocument, TProjection> options)
        {
            var projection         = options.Projection ?? new ClientSideDeserializationProjectionDefinition <TDocument, TProjection>();
            var renderedProjection = projection.Render(_documentSerializer, _settings.SerializerRegistry);

            return(new FindOneAndUpdateOperation <TProjection>(
                       _collectionNamespace,
                       filter.Render(_documentSerializer, _settings.SerializerRegistry),
                       update.Render(_documentSerializer, _settings.SerializerRegistry),
                       new FindAndModifyValueDeserializer <TProjection>(renderedProjection.ProjectionSerializer),
                       _messageEncoderSettings)
            {
                BypassDocumentValidation = options.BypassDocumentValidation,
                Collation = options.Collation,
                IsUpsert = options.IsUpsert,
                MaxTime = options.MaxTime,
                Projection = renderedProjection.Document,
                ReturnDocument = options.ReturnDocument.ToCore(),
                Sort = options.Sort == null ? null : options.Sort.Render(_documentSerializer, _settings.SerializerRegistry),
                WriteConcern = _settings.WriteConcern
            });
        }
        public override Task <TProjection> FindOneAndUpdateAsync <TProjection>(FilterDefinition <TDocument> filter, UpdateDefinition <TDocument> update, FindOneAndUpdateOptions <TDocument, TProjection> options, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(filter, nameof(filter));
            Ensure.IsNotNull(update, nameof(update));
            options = options ?? new FindOneAndUpdateOptions <TDocument, TProjection>();

            var operation = CreateFindOneAndUpdateOperation(filter, update, options);

            return(ExecuteWriteOperationAsync(operation, cancellationToken));
        }