private CursorBatch <TDocument> ExecuteGetMoreCommand(IChannelHandle channel, CancellationToken cancellationToken)
        {
            var          command = CreateGetMoreCommand();
            BsonDocument result;

            try
            {
                result = channel.Command <BsonDocument>(
                    _channelSource.Session,
                    null, // readPreference
                    _collectionNamespace.DatabaseNamespace,
                    command,
                    null, // commandPayloads
                    NoOpElementNameValidator.Instance,
                    null, // additionalOptions
                    null, // postWriteAction
                    CommandResponseHandling.Return,
                    __getMoreCommandResultSerializer,
                    _messageEncoderSettings,
                    cancellationToken);
            }
            catch (MongoCommandException ex) when(IsMongoCursorNotFoundException(ex))
            {
                throw new MongoCursorNotFoundException(channel.ConnectionDescription.ConnectionId, _cursorId, command);
            }

            return(CreateCursorBatch(result));
        }
        private IReadOnlyList <BsonDocument> GetFirstBatchUsingFindCommand(IChannelHandle channel, BsonDocument query, int batchSize, CancellationToken cancellationToken, out long cursorId)
        {
            var command = new BsonDocument
            {
                { "find", _collectionNamespace.CollectionName },
                { "filter", query },
                { "batchSize", batchSize }
            };
            var result = channel.Command <BsonDocument>(
                _session,
                ReadPreference.Primary,
                _databaseNamespace,
                command,
                null, // payloads
                NoOpElementNameValidator.Instance,
                null, // additionalOptions
                null, // postWriteAction
                CommandResponseHandling.Return,
                BsonDocumentSerializer.Instance,
                _messageEncoderSettings,
                cancellationToken);
            var cursor     = result["cursor"].AsBsonDocument;
            var firstBatch = cursor["firstBatch"].AsBsonArray.Select(i => i.AsBsonDocument).ToList();

            cursorId = cursor["id"].ToInt64();
            return(firstBatch);
        }
 private BsonDocument ExecuteProtocol(IChannelHandle channel, BsonDocument command, Func <CommandResponseHandling> responseHandling, CancellationToken cancellationToken)
 {
     return(channel.Command <BsonDocument>(
                _collectionNamespace.DatabaseNamespace,
                command,
                NoOpElementNameValidator.Instance,
                responseHandling,
                false, // slaveOk
                BsonDocumentSerializer.Instance,
                _messageEncoderSettings,
                cancellationToken) ?? new BsonDocument("ok", 1));
 }
示例#4
0
        private CursorBatch <TDocument> ExecuteGetMoreCommand(IChannelHandle channel, CancellationToken cancellationToken)
        {
            var command = CreateGetMoreCommand();
            var result  = channel.Command <BsonDocument>(
                _collectionNamespace.DatabaseNamespace,
                command,
                NoOpElementNameValidator.Instance,
                () => CommandResponseHandling.Return,
                false, // slaveOk
                __getMoreCommandResultSerializer,
                _messageEncoderSettings,
                cancellationToken);

            return(CreateCursorBatch(result));
        }
示例#5
0
        private TCommandResult ExecuteProtocol(IChannelHandle channel, ServerDescription serverDescription, ReadPreference readPreference, CancellationToken cancellationToken)
        {
            var wrappedCommand = CreateWrappedCommand(serverDescription, readPreference);
            var slaveOk        = readPreference != null && readPreference.ReadPreferenceMode != ReadPreferenceMode.Primary;

            return(channel.Command <TCommandResult>(
                       _databaseNamespace,
                       wrappedCommand,
                       _commandValidator,
                       () => CommandResponseHandling.Return,
                       slaveOk,
                       _resultSerializer,
                       _messageEncoderSettings,
                       cancellationToken));
        }
示例#6
0
        private CursorBatch <TDocument> ExecuteProtocol(IChannelHandle channel, ServerDescription serverDescription, ReadPreference readPreference, bool slaveOk, CancellationToken cancellationToken)
        {
            var command = CreateCommand(serverDescription, readPreference);

            var result = channel.Command <BsonDocument>(
                _collectionNamespace.DatabaseNamespace,
                command,
                NoOpElementNameValidator.Instance,
                () => CommandResponseHandling.Return,
                slaveOk,
                __findCommandResultSerializer,
                _messageEncoderSettings,
                cancellationToken);

            return(CreateCursorBatch(result));
        }
示例#7
0
        // methods
        private TCommandResult ExecuteProtocol(IChannelHandle channel, ICoreSessionHandle session, ReadPreference readPreference, CancellationToken cancellationToken)
        {
            var additionalOptions = GetEffectiveAdditionalOptions();

            return(channel.Command(
                       session,
                       readPreference,
                       _databaseNamespace,
                       _command,
                       _commandValidator,
                       additionalOptions,
                       () => CommandResponseHandling.Return,
                       _resultSerializer,
                       _messageEncoderSettings,
                       cancellationToken));
        }
        private CursorBatch <TDocument> ExecuteGetMoreCommand(IChannelHandle channel, CancellationToken cancellationToken)
        {
            var command = CreateGetMoreCommand();
            var result  = channel.Command <BsonDocument>(
                _channelSource.Session,
                null, // readPreference
                _collectionNamespace.DatabaseNamespace,
                command,
                NoOpElementNameValidator.Instance,
                null, // additionalOptions
                () => CommandResponseHandling.Return,
                __getMoreCommandResultSerializer,
                _messageEncoderSettings,
                cancellationToken);

            return(CreateCursorBatch(result));
        }
        private void ExecuteKillCursorsCommand(IChannelHandle channel, CancellationToken cancellationToken)
        {
            var command = CreateKillCursorsCommand();
            var result  = channel.Command(
                _channelSource.Session,
                null, // readPreference
                _collectionNamespace.DatabaseNamespace,
                command,
                null, // commandPayloads
                NoOpElementNameValidator.Instance,
                null, // additionalOptions
                null, // postWriteAction
                CommandResponseHandling.Return,
                BsonDocumentSerializer.Instance,
                _messageEncoderSettings,
                cancellationToken);

            ThrowIfKillCursorsCommandFailed(result, channel.ConnectionDescription.ConnectionId);
        }