// methods internal BsonDocument CreateCommand(SemanticVersion serverVersion) { Feature.Collation.ThrowIfNotSupported(serverVersion, _collation); return(new BsonDocument { { "aggregate", _collectionNamespace.CollectionName }, { "explain", true }, { "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 } }); }
internal BsonDocument CreateCommand(ConnectionDescription connectionDescription, ICoreSession session) { Feature.ReadConcern.ThrowIfNotSupported(connectionDescription.ServerVersion, _readConcern); 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 } }); }
// 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", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue }, { "collation", () => _collation.ToBsonDocument(), _collation != null } }; ReadConcernHelper.AppendReadConcern(command, _readConcern, connectionDescription, session); return(command); }
// methods internal override BsonDocument CreateCommand(SemanticVersion serverVersion, long?transactionNumber) { Feature.Collation.ThrowIfNotSupported(serverVersion, Collation); 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.ToBsonDocument(), WriteConcern != null && !WriteConcern.IsServerDefault && Feature.FindAndModifyWriteConcern.IsSupported(serverVersion) }, { "collation", () => Collation.ToBsonDocument(), Collation != null }, { "txnNumber", () => transactionNumber, transactionNumber.HasValue } }); }
internal BsonDocument CreateCommand(SemanticVersion serverVersion) { Feature.Collation.ThrowIfNotSupported(serverVersion, _collation); return(new BsonDocument { { "aggregate", _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 }, { "writeConcern", () => _writeConcern.ToBsonDocument(), Feature.CommandsThatWriteAcceptWriteConcern.ShouldSendWriteConcern(serverVersion, _writeConcern) }, { "cursor", new BsonDocument(), serverVersion >= new SemanticVersion(3, 5, 0) }, { "hint", () => _hint, _hint != null }, { "comment", () => _comment, _comment != null } }); }
// private methods internal BsonDocument CreateCommand() { return(new BsonDocument { { "group", new BsonDocument { { "ns", _collectionNamespace.CollectionName }, { "key", _key, _key != null }, { "$keyf", _keyFunction, _keyFunction != null }, { "$reduce", _reduceFunction }, { "initial", _initial }, { "cond", _filter, _filter != null }, { "finalize", _finalizeFunction, _finalizeFunction != null }, { "collation", () => _collation.ToBsonDocument(), _collation != null } } }, { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue } }); }
// methods /// <summary> /// Creates the command. /// </summary> /// <param name="session">The session.</param> /// <param name="connectionDescription">The connection description.</param> /// <returns> /// The command. /// </returns> protected internal virtual BsonDocument CreateCommand(ICoreSessionHandle session, ConnectionDescription connectionDescription) { return(new BsonDocument { { "mapReduce", _collectionNamespace.CollectionName }, { "map", _mapFunction }, { "reduce", _reduceFunction }, { "out", CreateOutputOptions() }, { "query", _filter, _filter != null }, { "sort", _sort, _sort != null }, { "limit", () => _limit.Value, _limit.HasValue }, { "finalize", _finalizeFunction, _finalizeFunction != null }, { "scope", _scope, _scope != null }, { "jsMode", () => _javaScriptMode.Value, _javaScriptMode.HasValue }, { "verbose", () => _verbose.Value, _verbose.HasValue }, { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue }, { "collation", () => _collation.ToBsonDocument(), _collation != null } }); }
// 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 { { "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 }, { "readConcern", readConcern, readConcern != null } }); }
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 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 } }); }
// methods /// <summary> /// Creates the command. /// </summary> /// <param name="connectionDescription">The connection description.</param> /// <param name="session">The session.</param> /// <returns>The command.</returns> protected internal virtual BsonDocument CreateCommand(ConnectionDescription connectionDescription, ICoreSession session) { Feature.Collation.ThrowIfNotSupported(connectionDescription.ServerVersion, _collation); return(new BsonDocument { { "mapreduce", _collectionNamespace.CollectionName }, // all lowercase command name for backwards compatibility { "map", _mapFunction }, { "reduce", _reduceFunction }, { "out", CreateOutputOptions() }, { "query", _filter, _filter != null }, { "sort", _sort, _sort != null }, { "limit", () => _limit.Value, _limit.HasValue }, { "finalize", _finalizeFunction, _finalizeFunction != null }, { "scope", _scope, _scope != null }, { "jsMode", () => _javaScriptMode.Value, _javaScriptMode.HasValue }, { "verbose", () => _verbose.Value, _verbose.HasValue }, { "maxTimeMS", () => MaxTimeHelper.ToMaxTimeMS(_maxTime.Value), _maxTime.HasValue }, { "collation", () => _collation.ToBsonDocument(), _collation != null } }); }
// methods internal override BsonDocument CreateCommand(SemanticVersion serverVersion, long?transactionNumber) { Feature.Collation.ThrowIfNotSupported(serverVersion, Collation); 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.ToBsonDocument(), WriteConcern != null && !WriteConcern.IsServerDefault && Feature.FindAndModifyWriteConcern.IsSupported(serverVersion) }, { "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 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(ICoreSessionHandle session, ConnectionDescription connectionDescription) { var serverVersion = connectionDescription.ServerVersion; Feature.Collation.ThrowIfNotSupported(serverVersion, _collation); var writeConcern = WriteConcernHelper.GetWriteConcernForCommandThatWrites(session, _writeConcern, serverVersion); return(new BsonDocument { { "aggregate", _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 }, { "writeConcern", writeConcern, writeConcern != null }, { "cursor", new BsonDocument(), serverVersion >= new SemanticVersion(3, 5, 0) }, { "hint", () => _hint, _hint != null }, { "comment", () => _comment, _comment != null } }); }
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); }
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 } }); }
/// <summary> /// Sets the maximum time the server should spend on this query. /// </summary> /// <param name="maxTime">The max time.</param> /// <returns>The cursor (so you can chain method calls to it).</returns> public virtual MongoCursor SetMaxTime(TimeSpan maxTime) { if (_isFrozen) { ThrowFrozen(); } SetOption("$maxTimeMS", MaxTimeHelper.ToMaxTimeMS(maxTime)); return this; }