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));
        }
Exemple #2
0
        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,
                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
            });
        }