コード例 #1
0
        internal BsonDocument CreateCommand(ConnectionDescription connectionDescription, ICoreSession session)
        {
            Feature.ReadConcern.ThrowIfNotSupported(connectionDescription.ServerVersion, _readConcern);
            Feature.Collation.ThrowIfNotSupported(connectionDescription.ServerVersion, _collation);

            var command = new BsonDocument
            {
                { "aggregate", _collectionNamespace.CollectionName },
                { "pipeline", new BsonArray(_pipeline) },
                { "allowDiskUse", () => _allowDiskUse.Value, _allowDiskUse.HasValue },
                { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue },
                { "collation", () => _collation.ToBsonDocument(), _collation != null },
                { "hint", () => _hint, _hint != null },
                { "comment", () => _comment, _comment != null }
            };

            ReadConcernHelper.AppendReadConcern(command, _readConcern, connectionDescription, session);

            if (Feature.AggregateCursorResult.IsSupported(connectionDescription.ServerVersion))
            {
                var useCursor = _useCursor.GetValueOrDefault(true) || connectionDescription.ServerVersion >= new SemanticVersion(3, 5, 0);
                if (useCursor)
                {
                    command["cursor"] = new BsonDocument
                    {
                        { "batchSize", () => _batchSize.Value, _batchSize.HasValue }
                    };
                }
            }

            return(command);
        }
コード例 #2
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 }
            });
        }
コード例 #3
0
        /// <inheritdoc/>
        protected internal override BsonDocument CreateCommand(ConnectionDescription connectionDescription, ICoreSession session)
        {
            Feature.ReadConcern.ThrowIfNotSupported(connectionDescription.ServerVersion, _readConcern);

            var command = base.CreateCommand(connectionDescription, session);

            ReadConcernHelper.AppendReadConcern(command, _readConcern, connectionDescription, session);

            return(command);
        }
コード例 #4
0
        // methods
        internal BsonDocument CreateCommand(ConnectionDescription connectionDescription, ICoreSession session)
        {
            var readConcern = ReadConcernHelper.GetReadConcernForCommand(session, connectionDescription, _readConcern);

            return(new BsonDocument
            {
                { "parallelCollectionScan", _collectionNamespace.CollectionName },
                { "numCursors", _numberOfCursors },
                { "readConcern", readConcern, readConcern != null }
            });
        }
コード例 #5
0
        /// <inheritdoc/>
        protected internal override BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription)
        {
            var command = base.CreateCommand(session, connectionDescription);

            var readConcern = ReadConcernHelper.GetReadConcernForCommand(session, connectionDescription, _readConcern);

            if (readConcern != null)
            {
                command.Add("readConcern", readConcern);
            }

            return(command);
        }
コード例 #6
0
        public void GetReadConcernForCommand_should_consider_session_supported_when_logicalSessionTimeoutMinutes_is_null_and_load_balanced_mode()
        {
            var session = CreateSession(
                isInTransaction: false,
                isCausallyConsistent: true,
                operationTime: new BsonTimestamp(1234));
            var connectionDescription = CreateConnectionDescription(logicalSessionTimeoutMinutes: false, serviceId: true);
            var readConcern           = ReadConcern.FromBsonDocument(BsonDocument.Parse("{}"));

            var result = ReadConcernHelper.GetReadConcernForCommand(session, connectionDescription, readConcern);

            result.Should().Be(new BsonDocument("afterClusterTime", new BsonTimestamp(1234)));
        }
コード例 #7
0
        // methods
        internal BsonDocument CreateCommand(ConnectionDescription connectionDescription, ICoreSession session)
        {
            Feature.ReadConcern.ThrowIfNotSupported(connectionDescription.ServerVersion, _readConcern);

            var command = new BsonDocument
            {
                { "parallelCollectionScan", _collectionNamespace.CollectionName },
                { "numCursors", _numberOfCursors },
            };

            ReadConcernHelper.AppendReadConcern(command, _readConcern, connectionDescription, session);
            return(command);
        }
コード例 #8
0
        internal BsonDocument CreateCommand(ConnectionDescription connectionDescription, ICoreSession session)
        {
            var readConcern = ReadConcernHelper.GetReadConcernForCommand(session, connectionDescription, _readConcern);

            return(new BsonDocument
            {
                { "geoSearch", _collectionNamespace.CollectionName },
                { "near", _near, _near != null },
                { "limit", () => _limit.Value, _limit.HasValue },
                { "maxDistance", () => _maxDistance.Value, _maxDistance.HasValue },
                { "search", _search, _search != null },
                { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue },
                { "readConcern", readConcern, readConcern != null }
            });
        }
コード例 #9
0
        internal BsonDocument CreateCommand(ConnectionDescription connectionDescription, ICoreSession session)
        {
            Feature.ReadConcern.ThrowIfNotSupported(connectionDescription.ServerVersion, _readConcern);

            var command = new BsonDocument
            {
                { "geoSearch", _collectionNamespace.CollectionName },
                { "near", _near, _near != null },
                { "limit", () => _limit.Value, _limit.HasValue },
                { "maxDistance", () => _maxDistance.Value, _maxDistance.HasValue },
                { "search", _search, _search != null },
                { "maxTimeMS", () => _maxTime.Value.TotalMilliseconds, _maxTime.HasValue },
            };

            ReadConcernHelper.AppendReadConcern(command, _readConcern, connectionDescription, session);
            return(command);
        }
コード例 #10
0
        // private methods
        internal BsonDocument CreateCommand(ConnectionDescription connectionDescription, ICoreSession session)
        {
            Feature.ReadConcern.ThrowIfNotSupported(connectionDescription.ServerVersion, _readConcern);
            Feature.Collation.ThrowIfNotSupported(connectionDescription.ServerVersion, _collation);

            var command = new BsonDocument
            {
                { "distinct", _collectionNamespace.CollectionName },
                { "key", _fieldName },
                { "query", _filter, _filter != null },
                { "maxTimeMS", () => _maxTime.Value.TotalMilliseconds, _maxTime.HasValue },
                { "collation", () => _collation.ToBsonDocument(), _collation != null }
            };

            ReadConcernHelper.AppendReadConcern(command, _readConcern, connectionDescription, session);
            return(command);
        }
コード例 #11
0
ファイル: DistinctOperation.cs プロジェクト: LJM74520/nice
        // private methods
        internal BsonDocument CreateCommand(ConnectionDescription connectionDescription, ICoreSession session)
        {
            Feature.ReadConcern.ThrowIfNotSupported(connectionDescription.ServerVersion, _readConcern);
            Feature.Collation.ThrowIfNotSupported(connectionDescription.ServerVersion, _collation);

            var readConcern = ReadConcernHelper.GetReadConcernForCommand(session, connectionDescription, _readConcern);

            return(new BsonDocument
            {
                { "distinct", _collectionNamespace.CollectionName },
                { "key", _fieldName },
                { "query", _filter, _filter != null },
                { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue },
                { "collation", () => _collation.ToBsonDocument(), _collation != null },
                { "readConcern", readConcern, readConcern != null }
            });
        }
コード例 #12
0
        public void GetReadConcernForCommand_should_return_expected_result(
            bool isInTransaction,
            bool isCausallyConsistent,
            int?operationTime,
            string readConcernJson,
            string expectedResult)
        {
            var session = CreateSession(
                isInTransaction: isInTransaction,
                isCausallyConsistent: isCausallyConsistent,
                operationTime: operationTime.HasValue ? new BsonTimestamp(operationTime.Value) : null);
            var connectionDescription = CreateConnectionDescription(areSessionsSupported: true);
            var readConcern           = ReadConcern.FromBsonDocument(BsonDocument.Parse(readConcernJson));

            var result = ReadConcernHelper.GetReadConcernForCommand(session, connectionDescription, readConcern);

            result.Should().Be(expectedResult);
        }
コード例 #13
0
        public void GetReadConcernForFirstCommandInTransaction_should_return_expected_result(
            bool isCausallyConsistent,
            int?operationTime,
            string readConcernJson,
            string expectedResult)
        {
            var readConcern        = ReadConcern.FromBsonDocument(BsonDocument.Parse(readConcernJson));
            var transactionOptions = new TransactionOptions(readConcern);
            var transaction        = new CoreTransaction(1, transactionOptions);
            var session            = CreateSession(
                currentTransaction: transaction,
                isCausallyConsistent: isCausallyConsistent,
                operationTime: operationTime.HasValue ? new BsonTimestamp(operationTime.Value) : null);
            var connectionDescription = CreateConnectionDescription(logicalSessionTimeoutMinutes: true);

            var result = ReadConcernHelper.GetReadConcernForFirstCommandInTransaction(session, connectionDescription);

            result.Should().Be(expectedResult);
        }
コード例 #14
0
        internal BsonDocument CreateCommand(ConnectionDescription connectionDescription, ICoreSession session)
        {
            var readConcern = ReadConcernHelper.GetReadConcernForCommand(session, connectionDescription, _readConcern);

            return(new BsonDocument
            {
                { "geoNear", _collectionNamespace.CollectionName },
                { "near", _near },
                { "limit", () => _limit.Value, _limit.HasValue },
                { "maxDistance", () => _maxDistance.Value, _maxDistance.HasValue },
                { "query", _filter, _filter != null },
                { "spherical", () => _spherical.Value, _spherical.HasValue },
                { "distanceMultiplier", () => _distanceMultiplier.Value, _distanceMultiplier.HasValue },
                { "includeLocs", () => _includeLocs.Value, _includeLocs.HasValue },
                { "uniqueDocs", () => _uniqueDocs.Value, _uniqueDocs.HasValue },
                { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue },
                { "collation", () => _collation.ToBsonDocument(), _collation != null },
                { "readConcern", readConcern, readConcern != null }
            });
        }
        // methods
        internal BsonDocument CreateCommand(ConnectionDescription connectionDescription, ICoreSession session)
        {
            Feature.ReadConcern.ThrowIfNotSupported(connectionDescription.ServerVersion, _readConcern);
            Feature.Collation.ThrowIfNotSupported(connectionDescription.ServerVersion, _collation);

            var command = new BsonDocument
            {
                { "count", _collectionNamespace.CollectionName },
                { "query", _filter, _filter != null },
                { "limit", () => _limit.Value, _limit.HasValue },
                { "skip", () => _skip.Value, _skip.HasValue },
                { "hint", _hint, _hint != null },
                { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue },
                { "collation", () => _collation.ToBsonDocument(), _collation != null }
            };

            ReadConcernHelper.AppendReadConcern(command, _readConcern, connectionDescription, session);

            return(command);
        }
        public void ReadConcern_document_should_contain_the_expected_values(
            [Values(false, true)] bool supportsSessions,
            [Values(false, true)] bool causallyConsistent,
            [Values(null, 10L)] long?operationTime,
            [Values(null, ReadConcernLevel.Majority)] ReadConcernLevel?level)
        {
            var           connectionDescription = OperationTestHelper.CreateConnectionDescription(supportsSessions: supportsSessions);
            BsonTimestamp timestamp             = operationTime == null ? null : new BsonTimestamp(operationTime.Value);
            var           session = OperationTestHelper.CreateSession(causallyConsistent, timestamp);

            var readConcern = ReadConcern.Default;

            if (level != null)
            {
                readConcern = readConcern.With(level.Value);
            }

            var command = new BsonDocument();

            ReadConcernHelper.AppendReadConcern(command, readConcern, connectionDescription, session);

            if ((!supportsSessions || !causallyConsistent || operationTime == null) && level == null)
            {
                command.ElementCount.Should().Be(0);
            }
            else
            {
                command.Contains("readConcern").Should().BeTrue();
            }

            if (level != null)
            {
                command["readConcern"]["level"].AsString.Should().Be("majority");
            }

            if (supportsSessions && causallyConsistent && operationTime != null)
            {
                command["readConcern"]["afterClusterTime"].AsBsonTimestamp.Value.Should().Be(operationTime.Value);
            }
        }
コード例 #17
0
        // methods
        internal BsonDocument CreateCommand(ConnectionDescription connectionDescription, ICoreSession session)
        {
            Feature.ReadConcern.ThrowIfNotSupported(connectionDescription.ServerVersion, _readConcern);
            Feature.Collation.ThrowIfNotSupported(connectionDescription.ServerVersion, _collation);

            var firstBatchSize = _firstBatchSize ?? (_batchSize > 0 ? _batchSize : null);
            var isShardRouter  = connectionDescription.IsMasterResult.ServerType == ServerType.ShardRouter;

            var command = new BsonDocument
            {
                { "find", _collectionNamespace.CollectionName },
                { "filter", _filter, _filter != null },
                { "sort", _sort, _sort != null },
                { "projection", _projection, _projection != null },
                { "hint", _hint, _hint != null },
                { "skip", () => _skip.Value, _skip.HasValue },
                { "limit", () => Math.Abs(_limit.Value), _limit.HasValue&& _limit != 0 },
                { "batchSize", () => firstBatchSize.Value, firstBatchSize.HasValue },
                { "singleBatch", () => _limit < 0 || _singleBatch.Value, _limit < 0 || _singleBatch.HasValue },
                { "comment", _comment, _comment != null },
                { "maxScan", () => _maxScan.Value, _maxScan.HasValue },
                { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue },
                { "max", _max, _max != null },
                { "min", _min, _min != null },
                { "returnKey", () => _returnKey.Value, _returnKey.HasValue },
                { "showRecordId", () => _showRecordId.Value, _showRecordId.HasValue },
                { "snapshot", () => _snapshot.Value, _snapshot.HasValue },
                { "tailable", true, _cursorType == CursorType.Tailable || _cursorType == CursorType.TailableAwait },
                { "oplogReplay", () => _oplogReplay.Value, _oplogReplay.HasValue },
                { "noCursorTimeout", () => _noCursorTimeout.Value, _noCursorTimeout.HasValue },
                { "awaitData", true, _cursorType == CursorType.TailableAwait },
                { "allowPartialResults", () => _allowPartialResults.Value, _allowPartialResults.HasValue&& isShardRouter },
                { "collation", () => _collation.ToBsonDocument(), _collation != null }
            };

            ReadConcernHelper.AppendReadConcern(command, _readConcern, connectionDescription, session);

            return(command);
        }
        internal BsonDocument CreateCommand(ConnectionDescription connectionDescription, ICoreSession session)
        {
            Feature.ReadConcern.ThrowIfNotSupported(connectionDescription.ServerVersion, _readConcern);
            Feature.Collation.ThrowIfNotSupported(connectionDescription.ServerVersion, _collation);

            var command = new BsonDocument
            {
                { "geoNear", _collectionNamespace.CollectionName },
                { "near", _near },
                { "limit", () => _limit.Value, _limit.HasValue },
                { "maxDistance", () => _maxDistance.Value, _maxDistance.HasValue },
                { "query", _filter, _filter != null },
                { "spherical", () => _spherical.Value, _spherical.HasValue },
                { "distanceMultiplier", () => _distanceMultiplier.Value, _distanceMultiplier.HasValue },
                { "includeLocs", () => _includeLocs.Value, _includeLocs.HasValue },
                { "uniqueDocs", () => _uniqueDocs.Value, _uniqueDocs.HasValue },
                { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue },
                { "collation", () => _collation.ToBsonDocument(), _collation != null }
            };

            ReadConcernHelper.AppendReadConcern(command, _readConcern, connectionDescription, session);
            return(command);
        }
コード例 #19
0
        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 }
            });
        }