Exemplo n.º 1
0
        internal BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription)
        {
            var serverVersion = connectionDescription.ServerVersion;

            Feature.Collation.ThrowIfNotSupported(serverVersion, _collation);

            var readConcern = _readConcern != null
                ? ReadConcernHelper.GetReadConcernForCommand(session, connectionDescription, _readConcern)
                : null;

            var writeConcern = WriteConcernHelper.GetWriteConcernForCommandThatWrites(session, _writeConcern, serverVersion);

            return(new BsonDocument
            {
                { "aggregate", _collectionNamespace == null ? (BsonValue)1 : _collectionNamespace.CollectionName },
                { "pipeline", new BsonArray(_pipeline) },
                { "allowDiskUse", () => _allowDiskUse.Value, _allowDiskUse.HasValue },
                { "bypassDocumentValidation", () => _bypassDocumentValidation.Value, _bypassDocumentValidation.HasValue&& Feature.BypassDocumentValidation.IsSupported(serverVersion) },
                { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue },
                { "collation", () => _collation.ToBsonDocument(), _collation != null },
                { "readConcern", readConcern, readConcern != null },
                { "writeConcern", writeConcern, writeConcern != null },
                { "cursor", new BsonDocument(), serverVersion >= new SemanticVersion(3, 6, 0) },
                { "hint", () => _hint, _hint != null },
                { "comment", () => _comment, _comment != null }
            });
        }
Exemplo n.º 2
0
        // protected methods
        /// <inheritdoc />
        protected override BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription, int attempt, long?transactionNumber)
        {
            var serverVersion = connectionDescription.ServerVersion;

            if (!Feature.Collation.IsSupported(serverVersion))
            {
                if (_deletes.Items.Skip(_deletes.Offset).Take(_deletes.Count).Any(d => d.Collation != null))
                {
                    throw new NotSupportedException($"Server version {serverVersion} does not support collations.");
                }
            }
            if (Feature.HintForDeleteOperations.DriverMustThrowIfNotSupported(serverVersion) || (WriteConcern != null && !WriteConcern.IsAcknowledged))
            {
                if (_deletes.Items.Skip(_deletes.Offset).Take(_deletes.Count).Any(u => u.Hint != null))
                {
                    throw new NotSupportedException($"Server version {serverVersion} does not support hints.");
                }
            }

            var writeConcern = WriteConcernHelper.GetWriteConcernForWriteCommand(session, WriteConcern);

            return(new BsonDocument
            {
                { "delete", _collectionNamespace.CollectionName },
                { "ordered", IsOrdered },
                { "writeConcern", writeConcern, writeConcern != null },
                { "txnNumber", () => transactionNumber.Value, transactionNumber.HasValue }
            });
        }
Exemplo n.º 3
0
        // methods
        internal override BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription, long?transactionNumber)
        {
            var serverVersion = connectionDescription.ServerVersion;

            Feature.Collation.ThrowIfNotSupported(serverVersion, Collation);

            var writeConcern = WriteConcernHelper.GetWriteConcernForCommand(session, WriteConcern, serverVersion, Feature.FindAndModifyWriteConcern);

            return(new BsonDocument
            {
                { "findAndModify", CollectionNamespace.CollectionName },
                { "query", _filter },
                { "update", _update },
                { "new", true, _returnDocument == ReturnDocument.After },
                { "sort", _sort, _sort != null },
                { "fields", _projection, _projection != null },
                { "upsert", true, _isUpsert },
                { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue },
                { "writeConcern", writeConcern, writeConcern != null },
                { "bypassDocumentValidation", () => _bypassDocumentValidation.Value, _bypassDocumentValidation.HasValue&& Feature.BypassDocumentValidation.IsSupported(serverVersion) },
                { "collation", () => Collation.ToBsonDocument(), Collation != null },
                { "arrayFilters", () => new BsonArray(_arrayFilters), _arrayFilters != null },
                { "txnNumber", () => transactionNumber, transactionNumber.HasValue }
            });
        }
        // methods
        internal override BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription, long?transactionNumber)
        {
            var serverVersion = connectionDescription.ServerVersion;

            Feature.Collation.ThrowIfNotSupported(serverVersion, Collation);
            if (Feature.HintForFindAndModifyFeature.DriverMustThrowIfNotSupported(serverVersion) || (WriteConcern != null && !WriteConcern.IsAcknowledged))
            {
                if (_hint != null)
                {
                    throw new NotSupportedException($"Server version {serverVersion} does not support hints.");
                }
            }

            var writeConcern = WriteConcernHelper.GetWriteConcernForCommand(session, WriteConcern, serverVersion, Feature.FindAndModifyWriteConcern);

            return(new BsonDocument
            {
                { "findAndModify", CollectionNamespace.CollectionName },
                { "query", _filter },
                { "remove", true },
                { "sort", _sort, _sort != null },
                { "fields", _projection, _projection != null },
                { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue },
                { "writeConcern", writeConcern, writeConcern != null },
                { "collation", () => Collation.ToBsonDocument(), Collation != null },
                { "hint", _hint, _hint != null },
                { "txnNumber", () => transactionNumber, transactionNumber.HasValue }
            });
        }
        // protected methods
        /// <inheritdoc />
        protected override BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription, int attempt, long?transactionNumber)
        {
            var serverVersion = connectionDescription.ServerVersion;

            if (!Feature.Collation.IsSupported(serverVersion))
            {
                if (_updates.Items.Skip(_updates.Offset).Take(_updates.Count).Any(u => u.Collation != null))
                {
                    throw new NotSupportedException($"Server version {serverVersion} does not support collations.");
                }
            }
            if (!Feature.ArrayFilters.IsSupported(serverVersion))
            {
                if (_updates.Items.Skip(_updates.Offset).Take(_updates.Count).Any(u => u.ArrayFilters != null))
                {
                    throw new NotSupportedException($"Server version {serverVersion} does not support arrayFilters.");
                }
            }

            var writeConcern = WriteConcernHelper.GetWriteConcernForWriteCommand(session, WriteConcern);

            return(new BsonDocument
            {
                { "update", _collectionNamespace.CollectionName },
                { "ordered", IsOrdered },
                { "bypassDocumentValidation", () => _bypassDocumentValidation.Value, _bypassDocumentValidation.HasValue },
                { "writeConcern", writeConcern, writeConcern != null },
                { "txnNumber", () => transactionNumber.Value, transactionNumber.HasValue }
            });
        }
Exemplo n.º 6
0
        // methods
        internal override BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription, long?transactionNumber)
        {
            var maxWireVersion = connectionDescription.MaxWireVersion;

            if (Feature.HintForFindAndModifyFeature.DriverMustThrowIfNotSupported(maxWireVersion) || (WriteConcern != null && !WriteConcern.IsAcknowledged))
            {
                if (_hint != null)
                {
                    throw new NotSupportedException($"Server version {WireVersion.GetServerVersionForErrorMessage(maxWireVersion)} does not support hints.");
                }
            }

            var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, WriteConcern);

            return(new BsonDocument
            {
                { "findAndModify", CollectionNamespace.CollectionName },
                { "query", _filter },
                { "update", _update },
                { "new", true, _returnDocument == ReturnDocument.After },
                { "sort", _sort, _sort != null },
                { "fields", _projection, _projection != null },
                { "upsert", true, _isUpsert },
                { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue },
                { "writeConcern", writeConcern, writeConcern != null },
                { "bypassDocumentValidation", () => _bypassDocumentValidation.Value, _bypassDocumentValidation.HasValue },
                { "collation", () => Collation.ToBsonDocument(), Collation != null },
                { "comment", Comment, Comment != null },
                { "hint", _hint, _hint != null },
                { "arrayFilters", () => new BsonArray(_arrayFilters), _arrayFilters != null },
                { "txnNumber", () => transactionNumber, transactionNumber.HasValue },
                { "let", _let, _let != null }
            });
        }
Exemplo n.º 7
0
        // methods
        internal BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription)
        {
            var serverVersion = connectionDescription.ServerVersion;

            Feature.Collation.ThrowIfNotSupported(serverVersion, _collation);

            var flags        = GetFlags();
            var writeConcern = WriteConcernHelper.GetWriteConcernForCommandThatWrites(session, _writeConcern, serverVersion);

            return(new BsonDocument
            {
                { "create", _collectionNamespace.CollectionName },
                { "capped", () => _capped.Value, _capped.HasValue },
                { "autoIndexId", () => _autoIndexId.Value, _autoIndexId.HasValue },
                { "size", () => _maxSize.Value, _maxSize.HasValue },
                { "max", () => _maxDocuments.Value, _maxDocuments.HasValue },
                { "flags", () => (int)flags.Value, flags.HasValue },
                { "storageEngine", () => _storageEngine, _storageEngine != null },
                { "indexOptionDefaults", _indexOptionDefaults, _indexOptionDefaults != null },
                { "validator", _validator, _validator != null },
                { "validationAction", () => _validationAction.Value.ToString().ToLowerInvariant(), _validationAction.HasValue },
                { "validationLevel", () => _validationLevel.Value.ToString().ToLowerInvariant(), _validationLevel.HasValue },
                { "collation", () => _collation.ToBsonDocument(), _collation != null },
                { "writeConcern", writeConcern, writeConcern != null },
                { "expireAfterSeconds", () => _expireAfter.Value.TotalSeconds, _expireAfter.HasValue },
                { "timeseries", () => _timeSeriesOptions.ToBsonDocument(), _timeSeriesOptions != null }
            });
        }
Exemplo n.º 8
0
        // private methods
        internal BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription)
        {
            var writeConcern = WriteConcernHelper.GetWriteConcernForCommandThatWrites(session, _writeConcern, connectionDescription.ServerVersion);

            return(new BsonDocument
            {
                { "dropDatabase", 1 },
                { "writeConcern", writeConcern, writeConcern != null }
            });
        }
        // private methods
        internal BsonDocument CreateCommand(ICoreSessionHandle session)
        {
            var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern);

            return(new BsonDocument
            {
                { "dropDatabase", 1 },
                { "writeConcern", writeConcern, writeConcern != null }
            });
        }
        // private methods
        internal BsonDocument CreateCommand(ICoreSessionHandle session)
        {
            var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern);

            return(new BsonDocument
            {
                { "drop", _collectionNamespace.CollectionName },
                { "writeConcern", writeConcern, writeConcern != null }
            });
        }
Exemplo n.º 11
0
        // methods
        internal BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription)
        {
            var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern);

            return(new BsonDocument
            {
                { "renameCollection", _collectionNamespace.FullName },
                { "to", _newCollectionNamespace.FullName },
                { "dropTarget", () => _dropTarget.Value, _dropTarget.HasValue },
                { "writeConcern", writeConcern, writeConcern != null }
            });
        }
Exemplo n.º 12
0
        // methods
        internal BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription)
        {
            var writeConcern = WriteConcernHelper.GetWriteConcernForCommandThatWrites(session, _writeConcern, connectionDescription.ServerVersion);

            return(new BsonDocument
            {
                { "dropIndexes", _collectionNamespace.CollectionName },
                { "index", _indexName },
                { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue },
                { "writeConcern", writeConcern, writeConcern != null }
            });
        }
        // methods
        internal BsonDocument CreateCommand(ICoreSessionHandle session)
        {
            var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern);

            return(new BsonDocument
            {
                { "dropIndexes", _collectionNamespace.CollectionName },
                { "index", _indexName },
                { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue },
                { "writeConcern", writeConcern, writeConcern != null }
            });
        }
        public void GetWriteConcernForWriteCommand_should_return_expected_result(
            bool isInTransaction,
            string writeConcernJson,
            string expectedResult)
        {
            var session      = CreateSession(isInTransaction: isInTransaction);
            var writeConcern = writeConcernJson == null ? null : WriteConcern.FromBsonDocument(BsonDocument.Parse(writeConcernJson));

            var result = WriteConcernHelper.GetEffectiveWriteConcern(session, writeConcern);

            result.Should().Be(expectedResult);
        }
Exemplo n.º 15
0
        // private methods
        internal BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription)
        {
            var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern);

            return(new BsonDocument
            {
                { "create", _viewName },
                { "viewOn", _viewOn },
                { "pipeline", new BsonArray(_pipeline) },
                { "collation", () => _collation.ToBsonDocument(), _collation != null },
                { "writeConcern", writeConcern, writeConcern != null }
            });
        }
        // protected methods
        /// <inheritdoc />
        protected override BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription, int attempt, long?transactionNumber)
        {
            var writeConcern = WriteConcernHelper.GetWriteConcernForWriteCommand(session, WriteConcern);

            return(new BsonDocument
            {
                { "insert", _collectionNamespace.CollectionName },
                { "ordered", IsOrdered },
                { "bypassDocumentValidation", () => _bypassDocumentValidation, _bypassDocumentValidation.HasValue },
                { "writeConcern", writeConcern, writeConcern != null },
                { "txnNumber", () => transactionNumber.Value, transactionNumber.HasValue }
            });
        }
        // private methods
        internal BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription)
        {
            var serverVersion = connectionDescription.ServerVersion;
            var writeConcern  = WriteConcernHelper.GetWriteConcernForCommandThatWrites(session, _writeConcern, serverVersion);

            return(new BsonDocument
            {
                { "createIndexes", _collectionNamespace.CollectionName },
                { "indexes", new BsonArray(_requests.Select(request => request.CreateIndexDocument(serverVersion))) },
                { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue },
                { "writeConcern", writeConcern, writeConcern != null }
            });
        }
Exemplo n.º 18
0
        public void GetWriteConcernForCommandThatWrites_should_return_expected_result(
            bool isInTransaction,
            string writeConcernJson,
            bool featureIsSupported,
            string expectedResult)
        {
            var session       = CreateSession(isInTransaction: isInTransaction);
            var writeConcern  = writeConcernJson == null ? null : WriteConcern.FromBsonDocument(BsonDocument.Parse(writeConcernJson));
            var serverVersion = Feature.CommandsThatWriteAcceptWriteConcern.SupportedOrNotSupportedVersion(featureIsSupported);

            var result = WriteConcernHelper.GetWriteConcernForCommandThatWrites(session, writeConcern, serverVersion);

            result.Should().Be(expectedResult);
        }
        // methods
        /// <inheritdoc/>
        protected internal override BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription)
        {
            var command = base.CreateCommand(session, connectionDescription);

            if (_bypassDocumentValidation.HasValue)
            {
                command.Add("bypassDocumentValidation", _bypassDocumentValidation.Value);
            }
            var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern);

            if (writeConcern != null)
            {
                command.Add("writeConcern", writeConcern.ToBsonDocument());
            }
            return(command);
        }
Exemplo n.º 20
0
        // private methods
        internal BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription)
        {
            var serverVersion = connectionDescription.ServerVersion;

            Feature.Views.ThrowIfNotSupported(serverVersion);
            Feature.Collation.ThrowIfNotSupported(serverVersion, _collation);

            var writeConcern = WriteConcernHelper.GetWriteConcernForCommandThatWrites(session, _writeConcern, serverVersion);

            return(new BsonDocument
            {
                { "create", _viewName },
                { "viewOn", _viewOn },
                { "pipeline", new BsonArray(_pipeline) },
                { "collation", () => _collation.ToBsonDocument(), _collation != null },
                { "writeConcern", writeConcern, writeConcern != null }
            });
        }
Exemplo n.º 21
0
        // methods
        /// <inheritdoc/>
        protected internal override BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription)
        {
            var command = base.CreateCommand(session, connectionDescription);

            var serverVersion = connectionDescription.ServerVersion;

            if (_bypassDocumentValidation.HasValue && Feature.BypassDocumentValidation.IsSupported(serverVersion))
            {
                command.Add("bypassDocumentValidation", _bypassDocumentValidation.Value);
            }
            var writeConcern = WriteConcernHelper.GetWriteConcernForCommandThatWrites(session, _writeConcern, serverVersion);

            if (writeConcern != null)
            {
                command.Add("writeConcern", writeConcern.ToBsonDocument());
            }
            return(command);
        }
Exemplo n.º 22
0
        // methods
        internal override BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription, long?transactionNumber)
        {
            var serverVersion = connectionDescription.ServerVersion;

            Feature.Collation.ThrowIfNotSupported(serverVersion, Collation);

            var writeConcern = WriteConcernHelper.GetWriteConcernForCommand(session, WriteConcern, serverVersion, Feature.FindAndModifyWriteConcern);

            return(new BsonDocument
            {
                { "findAndModify", CollectionNamespace.CollectionName },
                { "query", _filter },
                { "remove", true },
                { "sort", _sort, _sort != null },
                { "fields", _projection, _projection != null },
                { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue },
                { "writeConcern", writeConcern, writeConcern != null },
                { "collation", () => Collation.ToBsonDocument(), Collation != null },
                { "txnNumber", () => transactionNumber, transactionNumber.HasValue }
            });
        }
        // protected methods
        /// <inheritdoc />
        protected override BsonDocument CreateCommand(ICoreSessionHandle session, int attempt, long?transactionNumber)
        {
            if (WriteConcern != null && !WriteConcern.IsAcknowledged)
            {
                if (_deletes.Items.Skip(_deletes.Offset).Take(_deletes.Count).Any(u => u.Hint != null))
                {
                    throw new NotSupportedException("Hint is not supported for unacknowledged writes.");
                }
            }

            var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, WriteConcern);

            return(new BsonDocument
            {
                { "delete", _collectionNamespace.CollectionName },
                { "ordered", IsOrdered },
                { "writeConcern", writeConcern, writeConcern != null },
                { "txnNumber", () => transactionNumber.Value, transactionNumber.HasValue },
                { "let", _let, _let != null }
            });
        }
        internal BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription)
        {
            var readConcern = _readConcern != null
                ? ReadConcernHelper.GetReadConcernForCommand(session, connectionDescription, _readConcern)
                : null;

            var writeConcern = WriteConcernHelper.GetEffectiveWriteConcern(session, _writeConcern);

            return(new BsonDocument
            {
                { "aggregate", _collectionNamespace == null ? (BsonValue)1 : _collectionNamespace.CollectionName },
                { "pipeline", new BsonArray(_pipeline) },
                { "allowDiskUse", () => _allowDiskUse.Value, _allowDiskUse.HasValue },
                { "bypassDocumentValidation", () => _bypassDocumentValidation.Value, _bypassDocumentValidation.HasValue },
                { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue },
                { "collation", () => _collation.ToBsonDocument(), _collation != null },
                { "readConcern", readConcern, readConcern != null },
                { "writeConcern", writeConcern, writeConcern != null },
                { "cursor", new BsonDocument() },
                { "hint", () => _hint, _hint != null },
                { "let", () => _let, _let != null },
                { "comment", () => _comment, _comment != null }
            });
        }