case class MapReduceObservable[TResult](wrapped: MapReducePublisher[TResult]) extends Observable[TResult] with Product with Serializable
Observable for map reduce.
- Annotations
- @deprecated
- Deprecated
Superseded by aggregate
- Alphabetic
- By Inheritance
- MapReduceObservable
- Serializable
- Product
- Equals
- Observable
- Publisher
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new MapReduceObservable(wrapped: MapReducePublisher[TResult])
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def action(action: MapReduceAction): MapReduceObservable[TResult]
Specify the
MapReduceAction
to be used when writing to a collection.Specify the
MapReduceAction
to be used when writing to a collection.- action
an model.MapReduceAction to perform on the collection
- returns
this
- def andThen[U](pf: PartialFunction[Try[TResult], U]): Observable[TResult]
Applies the side-effecting function to the final result of this Observable and, returns a new Observable with the result of this Observable.
Applies the side-effecting function to the final result of this Observable and, returns a new Observable with the result of this Observable.
This method allows one to enforce that the callbacks are executed in a specified order.
Note that if one of the chained
andThen
callbacks throws an exception, that exception is not propagated to the subsequentandThen
callbacks. Instead, the subsequentandThen
callbacks are given the original value of this Observable.The following example prints out
10
:Observable(1 to 10) andThen { case r => sys.error("runtime exception") } andThen { case Success(x) => print(x) case Failure(t) => print("Failure") }
- U
the result type of the
- pf
the partial function to pattern match against
- returns
an
- Definition Classes
- Observable
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def batchSize(batchSize: Int): MapReduceObservable[TResult]
Sets the number of documents to return per batch.
Sets the number of documents to return per batch.
- batchSize
the batch size
- returns
this
- Since
2.7
- def bypassDocumentValidation(bypassDocumentValidation: Boolean): MapReduceObservable[TResult]
Sets the bypass document level validation flag.
Sets the bypass document level validation flag.
Note:: This only applies when an
$out
stage is specified.- bypassDocumentValidation
If true, allows the write to opt-out of document level validation.
- returns
this
- Since
1.1
- Note
Requires MongoDB 3.2 or greater
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @IntrinsicCandidate()
- def collation(collation: Collation): MapReduceObservable[TResult]
Sets the collation options
Sets the collation options
- collation
the collation options to use
- returns
this
- Since
1.2
- Note
A null value represents the server default.
,Requires MongoDB 3.4 or greater
- def collect[S](pf: PartialFunction[TResult, S]): Observable[S]
Builds a new Observable by applying a partial function to all elements.
Builds a new Observable by applying a partial function to all elements.
Example:
val justStrings = Observable(Iterable("this", 1, 2, "that")).collect{ case s: String => s }
- S
the resulting type of each item in the Observable
- pf
function that transforms each result of the receiver into an Observable and passes each result of that Observable to the returned Observable.
- returns
an Observable with transformed results and / or error.
- Definition Classes
- Observable
- def collect[S](): SingleObservable[Seq[TResult]]
Collects all the values of the Observable into a list and returns a new Observable with that list.
Collects all the values of the Observable into a list and returns a new Observable with that list.
Example:
val listOfNumbers = Observable(1 to 100).collect()
- returns
an Observable that emits a single item, the result of accumulator.
- Definition Classes
- Observable
- Note
If the Observable is large then this will consume lots of memory! If the underlying Observable is infinite this Observable will never complete.
- See also
Uses foldLeft underneath
- def collectionName(collectionName: String): MapReduceObservable[TResult]
Sets the collectionName for the output of the MapReduce
Sets the collectionName for the output of the MapReduce
The default action is replace the collection if it exists, to change this use action.
- collectionName
the name of the collection that you want the map-reduce operation to write its output.
- returns
this
- def completeWithUnit(): SingleObservable[Unit]
Convert this observable so that it emits a single Unit to Observer.onNext before calling Observer.onComplete.
Convert this observable so that it emits a single Unit to Observer.onNext before calling Observer.onComplete.
If the underlying observable errors then that is propagated to the
Observer
. This method is especially useful for chainingObservable[Void]
in for comprehensions.- returns
a single observable which emits Unit before completion.
- Definition Classes
- Observable
- Since
4.4
- def databaseName(databaseName: String): MapReduceObservable[TResult]
Sets the name of the database to output into.
Sets the name of the database to output into.
- databaseName
the name of the database to output into.
- returns
this
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def fallbackTo[U >: TResult](that: Observable[U]): Observable[U]
Creates a new Observable which returns the results of this Observable, if there is an error, it will then fallback to returning the results of the alternative "
that
" Observable.Creates a new Observable which returns the results of this Observable, if there is an error, it will then fallback to returning the results of the alternative "
that
" Observable.If both Observables fail, the resulting Observable holds the throwable object of the first Observable.
Example:
val fallBackObservable = Observable(1 to 100) fallbackTo Observable(200 to 300)
Ensuring results from a Single Observer
fallbackTo
can potentially emit results from either Observer. This often isn't desirable, so to ensure only a single Observable issues results combine with the collect[S]()* method eg:val results = Observable(1 to 100).collect() fallbackTo Observable(200 to 300).collect()
- U
the type of the returned Observable
- that
the Observable to fallback to if
this
Observable fails- returns
an Observable that will fallback to the
that
Observable shouldthis
Observable complete with anonError
.
- Definition Classes
- Observable
- def filter(filter: Bson): MapReduceObservable[TResult]
Sets the query filter to apply to the query.
Sets the query filter to apply to the query.
- filter
the filter to apply to the query.
- returns
this
- def filter(predicate: (TResult) => Boolean): Observable[TResult]
Creates a new Observable by filtering the value of the current Observable with a predicate.
Creates a new Observable by filtering the value of the current Observable with a predicate.
If the current Observable fails, then the resulting Observable also fails.
Example:
val oddValues = Observable(1 to 100) filter { _ % 2 == 1 }
- predicate
the function that is applied to each result emitted if it matches that result is passes to the returned Observable
- returns
an Observable only containing items matching that match the predicate
- Definition Classes
- Observable
- def finalizeFunction(finalizeFunction: String): MapReduceObservable[TResult]
Sets the JavaScript function that follows the reduce method and modifies the output.
Sets the JavaScript function that follows the reduce method and modifies the output.
- finalizeFunction
the JavaScript function that follows the reduce method and modifies the output.
- returns
this
- def first(): SingleObservable[TResult]
Helper to return a single observable limited to the first result.
Helper to return a single observable limited to the first result.
- returns
a single observable which will the first result.
- Since
4.0
- def flatMap[S](mapFunction: (TResult) => Observable[S]): Observable[S]
Creates a new Observable by applying a function to each emitted result of the Observable.
Creates a new Observable by applying a function to each emitted result of the Observable. If the Observable calls errors then then the new Observable will also contain this exception.
As each emitted item passed to
onNext
returns an Observable, we tightly control the requests to the parent Observable. The requested amount is then passed to the child Observable and only when that is completed does the parent become available for requesting more data.Example:
def f = Observable(1 to 10) def g = Observable(100 to 100) val h = for { x: Int <- f // returns Observable(1 to 10) y: Int <- g // returns Observable(100 to 100) } yield x + y
is translated to:
f flatMap { (x: Int) => g map { (y: Int) => x + y } }
- S
the resulting type of each item in the Observable
- mapFunction
function that transforms a each result of the receiver into an Observable and passes each result of that Observable to the returned Observable.
- returns
an Observable with transformed results and / or error.
- Definition Classes
- Observable
- def foldLeft[S](initialValue: S)(accumulator: (S, TResult) => S): SingleObservable[S]
Creates a new Observable that contains the single result of the applied accumulator function.
Creates a new Observable that contains the single result of the applied accumulator function.
The first item emitted by the Observable is passed to the supplied accumulator function alongside the initial value, then all other emitted items are passed along with the previous result of the accumulator function.
Example:
val countingObservable = Observable(1 to 100) foldLeft(0)((v, i) => v + 1)
- initialValue
the initial (seed) accumulator value
- accumulator
an accumulator function to be invoked on each item emitted by the source Observable, the result of which will be used in the next accumulator call.
- returns
an Observable that emits a single item, the result of accumulator.
- Definition Classes
- Observable
- Note
If this function is used to collect results into a collection then it could use lots of memory! If the underlying Observable is infinite this Observable will never complete.
- def foreach[U](doOnEach: (TResult) => U): Unit
Applies a function applied to each emitted result.
Applies a function applied to each emitted result.
Automatically requests all results
- U
the resulting type after the transformation
- doOnEach
the anonymous function applied to each emitted item
- Definition Classes
- Observable
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- def head(): Future[TResult]
Returns the head of the Observable in a
scala.concurrent.Future
.Returns the head of the Observable in a
scala.concurrent.Future
.- returns
the head result of the Observable.
- Definition Classes
- Observable
- def headOption(): Future[Option[TResult]]
Returns the head option of the Observable in a
scala.concurrent.Future
.Returns the head option of the Observable in a
scala.concurrent.Future
.- returns
the head option result of the Observable.
- Definition Classes
- Observable
- Since
2.2
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def jsMode(jsMode: Boolean): MapReduceObservable[TResult]
Sets the flag that specifies whether to convert intermediate data into BSON format between the execution of the map and reduce functions.
Sets the flag that specifies whether to convert intermediate data into BSON format between the execution of the map and reduce functions. Defaults to false.
- jsMode
the flag that specifies whether to convert intermediate data into BSON format between the execution of the map and reduce functions
- returns
jsMode
- def limit(limit: Int): MapReduceObservable[TResult]
Sets the limit to apply.
Sets the limit to apply.
- limit
the limit, which may be null
- returns
this
- def map[S](mapFunction: (TResult) => S): Observable[S]
Creates a new Observable by applying a function to each emitted result of the Observable.
Creates a new Observable by applying a function to each emitted result of the Observable. If the Observable calls errors then then the new Observable will also contain this exception.
Example:
def f = Observable(1 to 10) def g = Observable(100 to 100) val h = for { x: Int <- f // returns Observable(1 to 10) y: Int <- g // returns Observable(100 to 100) } yield x + y
is translated to:
f flatMap { (x: Int) => g map { (y: Int) => x + y } }
- S
the resulting type of each item in the Observable
- mapFunction
function that transforms a each result of the receiver and passes the result to the returned Observable
- returns
an Observable with transformed results and / or error.
- Definition Classes
- Observable
- def maxTime(duration: Duration): MapReduceObservable[TResult]
Sets the maximum execution time on the server for this operation.
Sets the maximum execution time on the server for this operation.
- duration
the duration
- returns
this
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- def observeOn(context: ExecutionContext): Observable[TResult]
Use a specific execution context for future operations
Use a specific execution context for future operations
- context
the execution context
- returns
an Observable that uses the specified execution context
- Definition Classes
- Observable
- def productElementNames: Iterator[String]
- Definition Classes
- Product
- def recover[U >: TResult](pf: PartialFunction[Throwable, U]): Observable[U]
Creates a new Observable that will handle any matching throwable that this Observable might contain.
Creates a new Observable that will handle any matching throwable that this Observable might contain. If there is no match, or if this Observable contains a valid result then the new Observable will contain the same.
Example:
mongoExceptionObservable recover { case e: MongoException => 0 } // final result: 0 mongoExceptionObservable recover { case e: NotFoundException => 0 } // result: exception
- U
the type of the returned Observable
- pf
the partial function used to pattern match against the
onError
throwable- returns
an Observable that will handle any matching throwable and not error.
- Definition Classes
- Observable
- def recoverWith[U >: TResult](pf: PartialFunction[Throwable, Observable[U]]): Observable[U]
Creates a new Observable that will handle any matching throwable that this Observable might contain by assigning it a value of another Observable.
Creates a new Observable that will handle any matching throwable that this Observable might contain by assigning it a value of another Observable.
If there is no match, or if this Observable contains a valid result then the new Observable will contain the same result.
Example:
successfulObservable recoverWith { case e: ArithmeticException => observableB } // result: successfulObservable mongoExceptionObservable recoverWith { case t: Throwable => observableB } // result: observableB
Ensuring results from a Single Observer
recoverWith
can potentially emit results from either Observer. This often isn't desirable, so to ensure only a single Observable issues results combine with the collect[S]()* method eg:val results = Observable(1 to 100) .collect() .recoverWith({ case t: Throwable => Observable(200 to 300).collect() }) .subscribe((i: Seq[Int]) => print(results))
- U
the type of the returned Observable
- pf
the partial function used to pattern match against the
onError
throwable- returns
an Observable that will handle any matching throwable and not error but recover with a new observable
- Definition Classes
- Observable
- def scope(scope: Bson): MapReduceObservable[TResult]
Sets the global variables that are accessible in the map, reduce and finalize functions.
Sets the global variables that are accessible in the map, reduce and finalize functions.
- scope
the global variables that are accessible in the map, reduce and finalize functions.
- returns
this
- def sort(sort: Bson): MapReduceObservable[TResult]
Sets the sort criteria to apply to the query.
Sets the sort criteria to apply to the query.
- sort
the sort criteria, which may be null.
- returns
this
- def subscribe(observer: Observer[_ >: TResult]): Unit
Request
Observable
to start streaming data.Request
Observable
to start streaming data.This is a "factory method" and can be called multiple times, each time starting a new Subscription. Each
Subscription
will work for only a single Observer.If the
Observable
rejects the subscription attempt or otherwise fails it will signal the error via Observer.onError.- observer
the
Observer
that will consume signals from thisObservable
- Definition Classes
- MapReduceObservable → Observable
- def subscribe(doOnNext: (TResult) => Any, doOnError: (Throwable) => Any, doOnComplete: () => Any): Unit
Subscribes to the Observable and requests
Long.MaxValue
.Subscribes to the Observable and requests
Long.MaxValue
.Uses the default or overridden
onNext
,onError
,onComplete
partial functions.- doOnNext
anonymous function to apply to each emitted element.
- doOnError
anonymous function to apply if there is an error.
- doOnComplete
anonymous function to apply on completion.
- Definition Classes
- Observable
- def subscribe(doOnError: (Throwable) => Any, doOnComplete: () => Any): Unit
Subscribes to the Observable and requests
Long.MaxValue
.Subscribes to the Observable and requests
Long.MaxValue
.- doOnError
anonymous function to apply if there is an error.
- doOnComplete
anonymous function to apply on completion.
- Definition Classes
- Observable
- def subscribe(doOnNext: (TResult) => Any, doOnError: (Throwable) => Any): Unit
Subscribes to the Observable and requests
Long.MaxValue
.Subscribes to the Observable and requests
Long.MaxValue
.- doOnNext
anonymous function to apply to each emitted element.
- doOnError
anonymous function to apply if there is an error.
- Definition Classes
- Observable
- def subscribe(doOnNext: (TResult) => Any): Unit
Subscribes to the Observable and requests
Long.MaxValue
.Subscribes to the Observable and requests
Long.MaxValue
.- doOnNext
anonymous function to apply to each emitted element.
- Definition Classes
- Observable
- def subscribe(observer: Subscriber[_ >: TResult]): Unit
Handles the automatic boxing of a Java
Observable
so it conforms to the interface.Handles the automatic boxing of a Java
Observable
so it conforms to the interface.- observer
the
Observer
that will consume signals from thisObservable
- Definition Classes
- Observable → Publisher
- Note
Users should not have to implement this method but rather use the Scala
Observable
.
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toCollection(): SingleObservable[Void]
Aggregates documents to a collection according to the specified map-reduce function with the given options, which must specify a non-inline result.
Aggregates documents to a collection according to the specified map-reduce function with the given options, which must specify a non-inline result.
- returns
an empty Observable that indicates when the operation has completed Aggregation
- def transform[S](mapFunction: (TResult) => S, errorMapFunction: (Throwable) => Throwable): Observable[S]
Creates a new Observable by applying the
resultFunction
function to each emitted result.Creates a new Observable by applying the
resultFunction
function to each emitted result. If there is an error andonError
is called theerrorFunction
function is applied to the failed result.- S
the resulting type of each item in the Observable
- mapFunction
function that transforms a each result of the receiver and passes the result to the returned Observable
- errorMapFunction
function that transforms a failure of the receiver into a failure of the returned observer
- returns
an Observable with transformed results and / or error.
- Definition Classes
- Observable
- def verbose(verbose: Boolean): MapReduceObservable[TResult]
Sets whether to include the timing information in the result information.
Sets whether to include the timing information in the result information.
- verbose
whether to include the timing information in the result information.
- returns
this
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def withFilter(p: (TResult) => Boolean): Observable[TResult]
Used by for-comprehensions.
Used by for-comprehensions.
- Definition Classes
- Observable
- val wrapped: MapReducePublisher[TResult]
- def zip[U](that: Observable[U]): Observable[(TResult, U)]
Zips the values of
this
andthat
Observable, and creates a new Observable holding the tuple of their results.Zips the values of
this
andthat
Observable, and creates a new Observable holding the tuple of their results.If
this
Observable fails, the resulting Observable is failed with the throwable stored inthis
. Otherwise, ifthat
Observable fails, the resulting Observable is failed with the throwable stored inthat
.It will only emit as many items as the number of items emitted by the source Observable that emits the fewest items.
- U
the type of the
that
Observable- that
the Observable to zip with
- returns
a new zipped Observable
- Definition Classes
- Observable
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated
- def nonAtomic(nonAtomic: Boolean): MapReduceObservable[TResult]
Sets if the post-processing step will prevent MongoDB from locking the database.
Sets if the post-processing step will prevent MongoDB from locking the database.
Valid only with the
MapReduceAction.MERGE
orMapReduceAction.REDUCE
actions.- nonAtomic
if the post-processing step will prevent MongoDB from locking the database.
- returns
this
- Annotations
- @deprecated
- Deprecated
(Since version 4.1.0) This option will no longer be supported in MongoDB 4.4 as it will no longer hold a global or database level write lock
- def sharded(sharded: Boolean): MapReduceObservable[TResult]
Sets if the output database is sharded
Sets if the output database is sharded
- sharded
if the output database is sharded
- returns
this
- Annotations
- @deprecated
- Deprecated
(Since version 4.1.0) This option will no longer be supported in MongoDB 4.4.
This is the documentation for the MongoDB Scala driver.
Driver structure
The mongodb scala driver.
To get started you need a MongoClient instance, either from a connection string or via a org.mongodb.scala.MongoClientSettings.
Notable packages include: