Beispiel #1
0
        public void Aggregate_with_write_stage_should_not_have_transaction_id(
            [Values("$out", "$merge")] string outStage,
            [Values(false, true)] bool async)
        {
            RequireServer
            .Check()
            .ClusterTypes(ClusterType.ReplicaSet, ClusterType.Sharded)
            .Serverless(false);     // $out and $merge are not supported on serverless.

            if (outStage == "$merge")
            {
                RequireServer.Check().Supports(Feature.AggregateMerge);
            }

            DropAndCreateCollection();

            var eventCapturer = CreateEventCapturer();

            using (var client = CreateDisposableClient(eventCapturer))
            {
                var database   = client.GetDatabase(_databaseName);
                var collection = database.GetCollection <BsonDocument>(_collectionName);

                PipelineDefinition <BsonDocument, BsonDocument> pipeline = new EmptyPipelineDefinition <BsonDocument>();
                var outputCollection = database.GetCollection <BsonDocument>(_collectionName + "-outputCollection");
                switch (outStage)
                {
                case "$out":
                    pipeline = pipeline.Out(outputCollection);
                    break;

                case "$merge":
                    var mergeOptions = new MergeStageOptions <BsonDocument>();
                    pipeline = pipeline.Merge(outputCollection, mergeOptions);
                    break;

                default:
                    throw new Exception($"Unexpected outStage: {outStage}.");
                }
                if (async)
                {
                    collection.AggregateAsync(pipeline).GetAwaiter().GetResult();
                }
                else
                {
                    collection.Aggregate(pipeline);
                }

                AssertCommandDoesNotHaveTransactionId(eventCapturer);
            }
        }
Beispiel #2
0
        public void Merge_should_add_expected_stage()
        {
            var pipeline         = new EmptyPipelineDefinition <BsonDocument>();
            var client           = DriverTestConfiguration.Client;
            var outputDatabase   = client.GetDatabase("database");
            var outputCollection = outputDatabase.GetCollection <BsonDocument>("collection");
            var mergeOptions     = new MergeStageOptions <BsonDocument>();

            var result = pipeline.Merge(outputCollection, mergeOptions);

            var stages = RenderStages(result, BsonDocumentSerializer.Instance);

            stages.Count.Should().Be(1);
            stages[0].Should().Be("{ $merge : { into : { db : 'database', coll : 'collection' } } }");
        }