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); }
/// <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); }
// 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); }
// 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); }
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); }
// 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); } }
// 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); }