From 69ceb634c480cc373633088f41d19cdd131e76fd Mon Sep 17 00:00:00 2001 From: Ross Lawley Date: Wed, 6 Feb 2019 14:32:24 +0000 Subject: [PATCH] Revert "Revert "Support mode, db, and uniqueKey for aggregation $out stage"" This reverts commit 960b6db21dc81c193936fef749136f7aeac9520a. SCALA-473 --- .../org/mongodb/scala/model/Aggregates.scala | 12 +++++++++++- .../scala/org/mongodb/scala/model/package.scala | 16 ++++++++++++++++ .../org/mongodb/scala/model/AggregatesSpec.scala | 3 +++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/driver/src/main/scala/org/mongodb/scala/model/Aggregates.scala b/driver/src/main/scala/org/mongodb/scala/model/Aggregates.scala index 7895d38e..8e243a6a 100644 --- a/driver/src/main/scala/org/mongodb/scala/model/Aggregates.scala +++ b/driver/src/main/scala/org/mongodb/scala/model/Aggregates.scala @@ -339,11 +339,21 @@ object Aggregates { def unwind(fieldName: String, unwindOptions: UnwindOptions): Bson = JAggregates.unwind(fieldName, unwindOptions) /** - * Creates a `\$out` pipeline stage for the specified filter + * Creates a `\$out` pipeline stage that writes to the collection with the specified name * * @param collectionName the collection name * @return the `\$out` pipeline stage * @see [[http://docs.mongodb.org/manual/reference/operator/aggregation/out/ \$out]] */ def out(collectionName: String): Bson = JAggregates.out(collectionName) + + /** + * Creates a `\$out` pipeline stage that writes to the collection with the specified name, using the specified options + * + * @param collectionName the collection name + * @param options the options + * @return the `\$out` pipeline stage + * @see [[http://docs.mongodb.org/manual/reference/operator/aggregation/out/ \$out]] + */ + def out(collectionName: String, options: AggregateOutStageOptions): Bson = JAggregates.out(collectionName, options) } diff --git a/driver/src/main/scala/org/mongodb/scala/model/package.scala b/driver/src/main/scala/org/mongodb/scala/model/package.scala index e7465e2d..cd5020d3 100644 --- a/driver/src/main/scala/org/mongodb/scala/model/package.scala +++ b/driver/src/main/scala/org/mongodb/scala/model/package.scala @@ -79,6 +79,22 @@ package object model { def apply(): BucketOptions = new com.mongodb.client.model.BucketOptions() } + /** + * The options for a \$out aggregation pipeline stage + * + * @since 2.6 + */ + type AggregateOutStageOptions = com.mongodb.client.model.AggregateOutStageOptions + + /** + * The options for a \$out aggregation pipeline stage + * + * @since 2.6 + */ + object AggregateOutStageOptions { + def apply(): AggregateOutStageOptions = new com.mongodb.client.model.AggregateOutStageOptions() + } + /** * Granularity values for automatic bucketing. * diff --git a/driver/src/test/scala/org/mongodb/scala/model/AggregatesSpec.scala b/driver/src/test/scala/org/mongodb/scala/model/AggregatesSpec.scala index 5b377737..a58cbbbf 100644 --- a/driver/src/test/scala/org/mongodb/scala/model/AggregatesSpec.scala +++ b/driver/src/test/scala/org/mongodb/scala/model/AggregatesSpec.scala @@ -200,6 +200,9 @@ class AggregatesSpec extends FlatSpec with Matchers { it should "render $out" in { toBson(out("authors")) should equal(Document("""{ $out : "authors" }""")) + toBson(out("authors", AggregateOutStageOptions().databaseName("foo"))) should equal( + Document("""{ $out : {mode: "replaceCollection", to: "authors", db: "foo" } }""") + ) } it should "render $group" in {