Example #1
0
        private AsyncCursor <TResult> CreateCursor(IChannelSourceHandle channelSource, IChannelHandle channel, BsonDocument command, AggregateResult result)
        {
            if (SupportedFeatures.IsAggregateCursorResultSupported(channel.ConnectionDescription.ServerVersion) && _useCursor.GetValueOrDefault(true))
            {
                return(CreateCursorFromCursorResult(channelSource, command, result));
            }

            return(CreateCursorFromInlineResult(command, result));
        }
Example #2
0
        public void CreateCommand_should_create_the_correct_command(
            [Values("2.4.0", "2.6.0", "2.8.0", "3.0.0", "3.2.0")] string serverVersion,
            [Values(null, false, true)] bool?allowDiskUse,
            [Values(null, 10, 20)] int?batchSize,
            [Values(null, 2000)] int?maxTime,
            [Values(null, ReadConcernLevel.Local, ReadConcernLevel.Majority)] ReadConcernLevel?readConcernLevel,
            [Values(null, false, true)] bool?useCursor)
        {
            var semanticServerVersion = SemanticVersion.Parse(serverVersion);
            var subject = new AggregateOperation <BsonDocument>(_collectionNamespace, Enumerable.Empty <BsonDocument>(), BsonDocumentSerializer.Instance, _messageEncoderSettings)
            {
                AllowDiskUse = allowDiskUse,
                BatchSize    = batchSize,
                MaxTime      = maxTime.HasValue ? TimeSpan.FromMilliseconds(maxTime.Value) : (TimeSpan?)null,
                ReadConcern  = new ReadConcern(readConcernLevel),
                UseCursor    = useCursor
            };

            var expectedResult = new BsonDocument
            {
                { "aggregate", _collectionNamespace.CollectionName },
                { "pipeline", new BsonArray(subject.Pipeline) },
                { "allowDiskUse", () => allowDiskUse.Value, allowDiskUse.HasValue },
                { "maxTimeMS", () => maxTime.Value, maxTime.HasValue }
            };

            if (!subject.ReadConcern.IsServerDefault)
            {
                expectedResult["readConcern"] = subject.ReadConcern.ToBsonDocument();
            }

            if (SupportedFeatures.IsAggregateCursorResultSupported(semanticServerVersion) && useCursor.GetValueOrDefault(true))
            {
                expectedResult["cursor"] = new BsonDocument
                {
                    { "batchSize", () => batchSize.Value, batchSize.HasValue }
                };
            }

            if (!subject.ReadConcern.IsSupported(semanticServerVersion))
            {
                Action act = () => subject.CreateCommand(semanticServerVersion);
                act.ShouldThrow <MongoClientException>();
            }
            else
            {
                var result = subject.CreateCommand(semanticServerVersion);
                result.Should().Be(expectedResult);
            }
        }
Example #3
0
        internal BsonDocument CreateCommand(SemanticVersion serverVersion)
        {
            _readConcern.ThrowIfNotSupported(serverVersion);

            var command = new BsonDocument
            {
                { "aggregate", _collectionNamespace.CollectionName },
                { "pipeline", new BsonArray(_pipeline) },
                { "allowDiskUse", () => _allowDiskUse.Value, _allowDiskUse.HasValue },
                { "maxTimeMS", () => _maxTime.Value.TotalMilliseconds, _maxTime.HasValue },
                { "readConcern", () => _readConcern.ToBsonDocument(), !_readConcern.IsServerDefault }
            };

            if (SupportedFeatures.IsAggregateCursorResultSupported(serverVersion) && _useCursor.GetValueOrDefault(true))
            {
                command["cursor"] = new BsonDocument
                {
                    { "batchSize", () => _batchSize.Value, _batchSize.HasValue }
                };
            }
            return(command);
        }