Exemplo n.º 1
0
 /// <inheritdoc />
 public abstract Task <TProjection> FindOneAndReplaceAsync <TProjection>(FilterDefinition <TDocument> filter, TDocument replacement, FindOneAndReplaceOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken));
 public override TProjection FindOneAndReplace <TProjection>(FilterDefinition <TDocument> filter, TDocument replacement, FindOneAndReplaceOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(_wrappedCollection.FindOneAndReplace(CombineFilters(filter), replacement, options, cancellationToken));
 }
 public override Task <TProjection> FindOneAndReplaceAsync <TProjection>(IClientSessionHandle session, FilterDefinition <TDocument> filter, TDocument replacement, FindOneAndReplaceOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(_wrappedCollection.FindOneAndReplaceAsync(session, CombineFilters(filter), replacement, options, cancellationToken));
 }
Exemplo n.º 4
0
 /// <inheritdoc />
 public virtual Task <TProjection> FindOneAndReplaceAsync <TProjection>(IClientSessionHandle session, FilterDefinition <TDocument> filter, TDocument replacement, FindOneAndReplaceOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken))
 {
     throw new NotImplementedException();
 }
Exemplo n.º 5
0
        /// <summary>
        /// Finds a single document and replaces 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="replacement">The replacement.</param>
        /// <param name="options">The options.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// The result of the operation.
        /// </returns>
        public static Task <TResult> FindOneAndReplaceAsync <TDocument, TResult>(this IMongoCollection <TDocument> collection, Expression <Func <TDocument, bool> > filter, TDocument replacement, FindOneAndReplaceOptions <TResult> options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(collection, "collection");
            Ensure.IsNotNull(filter, "filter");

            return(collection.FindOneAndReplaceAsync(filter, replacement, options, cancellationToken));
        }
Exemplo n.º 6
0
        private FindOneAndReplaceOperation <TProjection> CreateFindOneAndReplaceOperation <TProjection>(FilterDefinition <TDocument> filter, object replacementObject, FindOneAndReplaceOptions <TDocument, TProjection> options)
        {
            var projection         = options.Projection ?? new ClientSideDeserializationProjectionDefinition <TDocument, TProjection>();
            var renderedProjection = projection.Render(_documentSerializer, _settings.SerializerRegistry);

            return(new FindOneAndReplaceOperation <TProjection>(
                       _collectionNamespace,
                       filter.Render(_documentSerializer, _settings.SerializerRegistry),
                       new BsonDocumentWrapper(replacementObject, _documentSerializer),
                       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
            });
        }
Exemplo n.º 7
0
        /// <inheritdoc />
        public virtual TProjection FindOneAndReplace <TProjection>(FilterDefinition <TDocument> filter, TDocument replacement, FindOneAndReplaceOptions <TDocument, TProjection> options = null, CancellationToken cancellationToken = default(CancellationToken))

        {
            throw new NotImplementedException();
        }
Exemplo n.º 8
0
        public override Task <TProjection> FindOneAndReplaceAsync <TProjection>(FilterDefinition <TDocument> filter, TDocument replacement, FindOneAndReplaceOptions <TDocument, TProjection> options, CancellationToken cancellationToken)
        {
            Ensure.IsNotNull(filter, nameof(filter));
            var replacementObject = Ensure.IsNotNull((object)replacement, nameof(replacement)); // only box once if it's a struct

            options = options ?? new FindOneAndReplaceOptions <TDocument, TProjection>();

            var operation = CreateFindOneAndReplaceOperation(filter, replacementObject, options);

            return(ExecuteWriteOperationAsync(operation, cancellationToken));
        }
Exemplo n.º 9
0
        public Task <TResult> FindOneAndReplaceAsync <TResult>(object filter, TDocument replacement, FindOneAndReplaceOptions <TResult> options, CancellationToken cancellationToken)
        {
            var replacementObject = (object)replacement; // only box once if it's a struct

            Ensure.IsNotNull(filter, "filter");
            Ensure.IsNotNull(replacementObject, "replacement");

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

            var operation = new FindOneAndReplaceOperation <TResult>(
                _collectionNamespace,
                ConvertFilterToBsonDocument(filter),
                ConvertToBsonDocument(replacementObject),
                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));
        }
Exemplo n.º 10
0
 public Task <TDocument> FindOneAndReplaceAsync(object filter, TDocument replacement, FindOneAndReplaceOptions <TDocument> options, CancellationToken cancellationToken)
 {
     return(FindOneAndReplaceAsync <TDocument>(filter, replacement, options, cancellationToken));
 }
Exemplo n.º 11
0
        /// <summary>
        /// Finds a single document and replaces 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="replacement">The replacement.</param>
        /// <param name="options">The options.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>
        /// The returned document.
        /// </returns>
        public static Task <TDocument> FindOneAndReplaceAsync <TDocument>(this IMongoCollection <TDocument> collection, Expression <Func <TDocument, bool> > filter, TDocument replacement, FindOneAndReplaceOptions <TDocument, TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            Ensure.IsNotNull(collection, nameof(collection));
            Ensure.IsNotNull(filter, nameof(filter));

            return(collection.FindOneAndReplaceAsync <TDocument>(new ExpressionFilterDefinition <TDocument>(filter), replacement, options, cancellationToken));
        }
Exemplo n.º 12
0
        public override Task <TProjection> FindOneAndReplaceAsync <TProjection>(FilterDefinition <TDocument> filter, TDocument replacement, FindOneAndReplaceOptions <TDocument, TProjection> options, CancellationToken cancellationToken)
        {
            var replacementObject = (object)replacement; // only box once if it's a struct

            Ensure.IsNotNull(filter, nameof(filter));
            Ensure.IsNotNull(replacementObject, nameof(replacementObject));

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

            var operation = new FindOneAndReplaceOperation <TProjection>(
                _collectionNamespace,
                filter.Render(_documentSerializer, _settings.SerializerRegistry),
                new BsonDocumentWrapper(replacementObject, _documentSerializer),
                new FindAndModifyValueDeserializer <TProjection>(renderedProjection.ProjectionSerializer),
                _messageEncoderSettings)
            {
                BypassDocumentValidation = options.BypassDocumentValidation,
                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
            };

            return(ExecuteWriteOperationAsync(operation, cancellationToken));
        }