Packages

c

org.mongodb.scala

FindObservable

case class FindObservable[TResult](wrapped: FindPublisher[TResult]) extends Observable[TResult] with Product with Serializable

Observable interface for Find.

TResult

The type of the result.

wrapped

the underlying java FindObservable

Since

1.0

Linear Supertypes
Serializable, Product, Equals, Observable[TResult], Publisher[TResult], AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. FindObservable
  2. Serializable
  3. Product
  4. Equals
  5. Observable
  6. Publisher
  7. AnyRef
  8. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new FindObservable(wrapped: FindPublisher[TResult])

    wrapped

    the underlying java FindObservable

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def allowDiskUse(allowDiskUse: Boolean): FindObservable[TResult]

    Enables writing to temporary files on the server.

    Enables writing to temporary files on the server. When set to true, the server can write temporary data to disk while executing the find operation.

    This option is sent only if the caller explicitly provides a value. The default is to not send a value. For servers < 3.2, this option is ignored and not sent as allowDiskUse does not exist in the OP_QUERY wire protocol.

    allowDiskUse

    the allowDiskUse

    Since

    4.1

    Note

    Requires MongoDB 4.4 or greater

  5. 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 subsequent andThen callbacks. Instead, the subsequent andThen 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
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def batchSize(batchSize: Int): FindObservable[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

  8. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @IntrinsicCandidate()
  9. def collation(collation: Collation): FindObservable[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

  10. 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
  11. 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

  12. def comment(comment: BsonValue): FindObservable[TResult]

    Sets the comment for this operation.

    Sets the comment for this operation. A null value means no comment is set.

    comment

    the comment

    returns

    this

    Since

    4.6

    Note

    The comment can be any valid BSON type for server versions 4.4 and above. Server versions between 3.6 and 4.2 only support string as comment, and providing a non-string type will result in a server-side error.

  13. def comment(comment: String): FindObservable[TResult]

    Sets the comment to the query.

    Sets the comment to the query. A null value means no comment is set.

    comment

    the comment

    returns

    this

    Since

    2.2

  14. def cursorType(cursorType: CursorType): FindObservable[TResult]

    Sets the cursor type.

    Sets the cursor type.

    cursorType

    the cursor type

    returns

    this

  15. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  16. def explain[ExplainResult](verbosity: ExplainVerbosity)(implicit e: DefaultsTo[ExplainResult, Document], ct: ClassTag[ExplainResult]): SingleObservable[ExplainResult]

    Explain the execution plan for this operation with the given verbosity level

    Explain the execution plan for this operation with the given verbosity level

    ExplainResult

    The type of the result

    verbosity

    the verbosity of the explanation

    returns

    the execution plan

    Since

    4.2

    Note

    Requires MongoDB 3.2 or greater

  17. def explain[ExplainResult]()(implicit e: DefaultsTo[ExplainResult, Document], ct: ClassTag[ExplainResult]): SingleObservable[ExplainResult]

    Explain the execution plan for this operation with the server's default verbosity level

    Explain the execution plan for this operation with the server's default verbosity level

    ExplainResult

    The type of the result

    returns

    the execution plan

    Since

    4.2

    Note

    Requires MongoDB 3.2 or greater

  18. 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 should this Observable complete with an onError.

    Definition Classes
    Observable
  19. def filter(filter: Bson): FindObservable[TResult]

    Sets the query filter to apply to the query.

    Sets the query filter to apply to the query.

    Filter

    filter

    the filter, which may be null.

    returns

    this

  20. 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
  21. def first(): SingleObservable[TResult]

    Helper to return a Observable limited to just the first result the query.

    Helper to return a Observable limited to just the first result the query.

    Note: Sets limit in the background so only returns 1.

    returns

    a Observable which will return the first item

  22. 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
  23. 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.

  24. 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
  25. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @IntrinsicCandidate()
  26. 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
  27. 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

  28. def hint(hint: Bson): FindObservable[TResult]

    Sets the hint for which index to use.

    Sets the hint for which index to use. A null value means no hint is set.

    hint

    the hint

    returns

    this

    Since

    2.2

  29. def hintString(hint: String): FindObservable[TResult]

    Sets the hint for which index to use.

    Sets the hint for which index to use. A null value means no hint is set.

    hint

    the name of the index which should be used for the operation

    returns

    this

    Since

    2.8

    Note

    if hint is set that will be used instead of any hint string.

  30. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  31. def let(let: Bson): FindObservable[TResult]

    Add top-level variables to the operation.

    Add top-level variables to the operation. A null value means no variables are set.

    Allows for improved command readability by separating the variables from the query text.

    let

    the top-level variables for the find operation or null

    returns

    this

    Since

    4.6

    Note

    Requires MongoDB 5.0 or greater

  32. def limit(limit: Int): FindObservable[TResult]

    Sets the limit to apply.

    Sets the limit to apply.

    Limit

    limit

    the limit, which may be null

    returns

    this

  33. 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
  34. def max(max: Bson): FindObservable[TResult]

    Sets the exclusive upper bound for a specific index.

    Sets the exclusive upper bound for a specific index. A null value means no max is set.

    max

    the max

    returns

    this

    Since

    2.2

  35. def maxAwaitTime(duration: Duration): FindObservable[TResult]

    The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query.

    The maximum amount of time for the server to wait on new documents to satisfy a tailable cursor query. This only applies to a TAILABLE_AWAIT cursor. When the cursor is not a TAILABLE_AWAIT cursor, this option is ignored.

    On servers >= 3.2, this option will be specified on the getMore command as "maxTimeMS". The default is no value: no "maxTimeMS" is sent to the server with the getMore command.

    On servers < 3.2, this option is ignored, and indicates that the driver should respect the server's default value

    A zero value will be ignored.

    Max Time

    duration

    the duration

    returns

    the maximum await execution time in the given time unit

    Since

    1.1

  36. def maxTime(duration: Duration): FindObservable[TResult]

    Sets the maximum execution time on the server for this operation.

    Sets the maximum execution time on the server for this operation.

    Max Time

    duration

    the duration

    returns

    this

  37. def min(min: Bson): FindObservable[TResult]

    Sets the minimum inclusive lower bound for a specific index.

    Sets the minimum inclusive lower bound for a specific index. A null value means no max is set.

    min

    the min

    returns

    this

    Since

    2.2

  38. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  39. def noCursorTimeout(noCursorTimeout: Boolean): FindObservable[TResult]

    The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use.

    The server normally times out idle cursors after an inactivity period (10 minutes) to prevent excess memory use. Set this option to prevent that.

    noCursorTimeout

    true if cursor timeout is disabled

    returns

    this

  40. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @IntrinsicCandidate()
  41. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @IntrinsicCandidate()
  42. 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
  43. def partial(partial: Boolean): FindObservable[TResult]

    Get partial results from a sharded cluster if one or more shards are unreachable (instead of throwing an error).

    Get partial results from a sharded cluster if one or more shards are unreachable (instead of throwing an error).

    partial

    if partial results for sharded clusters is enabled

    returns

    this

  44. def productElementNames: Iterator[String]
    Definition Classes
    Product
  45. def projection(projection: Bson): FindObservable[TResult]

    Sets a document describing the fields to return for all matching documents.

    Sets a document describing the fields to return for all matching documents.

    Projection

    projection

    the project document, which may be null.

    returns

    this

    See also

    org.mongodb.scala.model.Projections

  46. 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
  47. 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
  48. def returnKey(returnKey: Boolean): FindObservable[TResult]

    Sets the returnKey.

    Sets the returnKey. If true the find operation will return only the index keys in the resulting documents.

    returnKey

    the returnKey

    returns

    this

    Since

    2.2

  49. def showRecordId(showRecordId: Boolean): FindObservable[TResult]

    Sets the showRecordId.

    Sets the showRecordId. Set to true to add a field $recordId to the returned documents.

    showRecordId

    the showRecordId

    returns

    this

    Since

    2.2

  50. def skip(skip: Int): FindObservable[TResult]

    Sets the number of documents to skip.

    Sets the number of documents to skip.

    Skip

    skip

    the number of documents to skip

    returns

    this

  51. def sort(sort: Bson): FindObservable[TResult]

    Sets the sort criteria to apply to the query.

    Sets the sort criteria to apply to the query.

    Sort

    sort

    the sort criteria, which may be null.

    returns

    this

  52. 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 this Observable

    Definition Classes
    FindObservableObservable
  53. 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
  54. 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
  55. 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
  56. 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
  57. 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 this Observable

    Definition Classes
    Observable → Publisher
    Note

    Users should not have to implement this method but rather use the Scala Observable.

  58. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  59. 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 and onError is called the errorFunction 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
  60. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  61. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  62. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  63. final def withFilter(p: (TResult) => Boolean): Observable[TResult]

    Used by for-comprehensions.

    Used by for-comprehensions.

    Definition Classes
    Observable
  64. def zip[U](that: Observable[U]): Observable[(TResult, U)]

    Zips the values of this and that Observable, and creates a new Observable holding the tuple of their results.

    Zips the values of this and that 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 in this. Otherwise, if that Observable fails, the resulting Observable is failed with the throwable stored in that.

    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

  1. 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 chaining Observable[Void] in for comprehensions.

    returns

    a single observable which emits Unit before completion.

    Definition Classes
    Observable
    Annotations
    @deprecated
    Deprecated

    (Since version 5.0) Is no longer needed because of the ToSingleObservableUnit implicit class. Scheduled for removal in a major release

    Since

    4.4

  2. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from Observable[TResult]

Inherited from Publisher[TResult]

Inherited from AnyRef

Inherited from Any

Ungrouped