Skip to content

Commit

Permalink
Revert "Revert "Support mode, db, and uniqueKey for aggregation $out …
Browse files Browse the repository at this point in the history
…stage""

This reverts commit 960b6db.

SCALA-473
  • Loading branch information
rozza committed Feb 6, 2019
1 parent 87e7dd4 commit 69ceb63
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
12 changes: 11 additions & 1 deletion driver/src/main/scala/org/mongodb/scala/model/Aggregates.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
16 changes: 16 additions & 0 deletions driver/src/main/scala/org/mongodb/scala/model/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 69ceb63

Please sign in to comment.