Skip to content

Commit f936949

Browse files
committed
Support mode, db, and uniqueKey for aggregation $out stage
SCALA-473
1 parent 93e1ab4 commit f936949

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

driver/src/main/scala/org/mongodb/scala/model/Aggregates.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,11 +339,21 @@ object Aggregates {
339339
def unwind(fieldName: String, unwindOptions: UnwindOptions): Bson = JAggregates.unwind(fieldName, unwindOptions)
340340

341341
/**
342-
* Creates a `\$out` pipeline stage for the specified filter
342+
* Creates a `\$out` pipeline stage that writes to the collection with the specified name
343343
*
344344
* @param collectionName the collection name
345345
* @return the `\$out` pipeline stage
346346
* @see [[http://docs.mongodb.org/manual/reference/operator/aggregation/out/ \$out]]
347347
*/
348348
def out(collectionName: String): Bson = JAggregates.out(collectionName)
349+
350+
/**
351+
* Creates a `\$out` pipeline stage that writes to the collection with the specified name, using the specified options
352+
*
353+
* @param collectionName the collection name
354+
* @param options the options
355+
* @return the `\$out` pipeline stage
356+
* @see [[http://docs.mongodb.org/manual/reference/operator/aggregation/out/ \$out]]
357+
*/
358+
def out(collectionName: String, options: AggregateOutStageOptions): Bson = JAggregates.out(collectionName, options)
349359
}

driver/src/main/scala/org/mongodb/scala/model/package.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ package object model {
7979
def apply(): BucketOptions = new com.mongodb.client.model.BucketOptions()
8080
}
8181

82+
/**
83+
* The options for a \$out aggregation pipeline stage
84+
*
85+
* @since 2.6
86+
*/
87+
type AggregateOutStageOptions = com.mongodb.client.model.AggregateOutStageOptions
88+
89+
/**
90+
* The options for a \$out aggregation pipeline stage
91+
*
92+
* @since 2.6
93+
*/
94+
object AggregateOutStageOptions {
95+
def apply(): AggregateOutStageOptions = new com.mongodb.client.model.AggregateOutStageOptions()
96+
}
97+
8298
/**
8399
* Granularity values for automatic bucketing.
84100
*

driver/src/test/scala/org/mongodb/scala/model/AggregatesSpec.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ class AggregatesSpec extends FlatSpec with Matchers {
200200

201201
it should "render $out" in {
202202
toBson(out("authors")) should equal(Document("""{ $out : "authors" }"""))
203+
toBson(out("authors", AggregateOutStageOptions().databaseName("foo"))) should equal(
204+
Document("""{ $out : {mode: "replaceCollection", to: "authors", db: "foo" } }""")
205+
)
203206
}
204207

205208
it should "render $group" in {

0 commit comments

Comments
 (0)