Packages

final class QueryBuilder extends AnyRef

A builder that helps to make a fine-tuned query to MongoDB.

When the query is ready, you can call cursor to get a Cursor, or one if you want to retrieve just one document.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. QueryBuilder
  2. AnyRef
  3. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. def +(other: String): String
    Implicit
    This member is added by an implicit conversion from (QueryBuilderFactory.this)#QueryBuilder toany2stringadd[(QueryBuilderFactory.this)#QueryBuilder] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): ((QueryBuilderFactory.this)#QueryBuilder, B)
    Implicit
    This member is added by an implicit conversion from (QueryBuilderFactory.this)#QueryBuilder toArrowAssoc[(QueryBuilderFactory.this)#QueryBuilder] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  6. def allowPartialResults: (QueryBuilderFactory.this)#QueryBuilder

    Sets the partial flag.

    Sets the partial flag.

    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def allowPartial(c: BSONCollection) =
      c.find(BSONDocument.empty).allowPartialResults
  7. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  8. def awaitData: (QueryBuilderFactory.this)#QueryBuilder

    Makes the result cursor await data.

    Makes the result cursor await data.

    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def waitData(c: BSONCollection) =
      c.find(BSONDocument.empty).awaitData
  9. def batchSize(n: Int): (QueryBuilderFactory.this)#QueryBuilder

    Sets the size of result batches.

    Sets the size of result batches.

    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def tenBatch(c: BSONCollection) =
      c.find(BSONDocument.empty).batchSize(10)
  10. val batchSize: Int
  11. lazy val builder: Builder[(QueryBuilderFactory.this)#pack.type]
  12. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  13. def collation(collation: Collation): (QueryBuilderFactory.this)#QueryBuilder

    Sets the collation document.

    Sets the collation document.

    Since

    MongoDB 3.4

    import reactivemongo.api.Collation
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def foo(coll: BSONCollection, c: Collation) =
      coll.find(BSONDocument.empty).collation(c)
  14. val collation: Option[Collation]
  15. def comment(message: String): (QueryBuilderFactory.this)#QueryBuilder

    Adds a comment to this query, that may appear in the MongoDB logs.

    Adds a comment to this query, that may appear in the MongoDB logs.

    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def foo(coll: BSONCollection) = coll.find(BSONDocument.empty).
      comment("Any comment to trace the query")
  16. val comment: Option[String]
  17. def cursor[T](readPreference: ReadPreference = readPreference)(implicit reader: P.Reader[T], cp: CursorProducer[T]): ProducedCursor

    Returns a Cursor for the result of this query.

    Returns a Cursor for the result of this query.

    import scala.concurrent.{ ExecutionContext, Future }
    
    import reactivemongo.api.Cursor
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def findAllVisible(coll: BSONCollection)(
      implicit ec: ExecutionContext): Future[List[BSONDocument]] =
      coll.find(BSONDocument("visible" -> true)).
        cursor[BSONDocument]().collect[List](
         maxDocs = 10,
         err = Cursor.FailOnError[List[BSONDocument]]())
    T

    the results type

    readPreference

    The reactivemongo.api.ReadPreference for this query. If the ReadPreference implies that this query can be run on a secondary, the slaveOk flag will be set.

    reader

    the reader for the results type

  18. val cursorOptions: CursorOptions
  19. def ensuring(cond: ((QueryBuilderFactory.this)#QueryBuilder) => Boolean, msg: => Any): (QueryBuilderFactory.this)#QueryBuilder
    Implicit
    This member is added by an implicit conversion from (QueryBuilderFactory.this)#QueryBuilder toEnsuring[(QueryBuilderFactory.this)#QueryBuilder] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  20. def ensuring(cond: ((QueryBuilderFactory.this)#QueryBuilder) => Boolean): (QueryBuilderFactory.this)#QueryBuilder
    Implicit
    This member is added by an implicit conversion from (QueryBuilderFactory.this)#QueryBuilder toEnsuring[(QueryBuilderFactory.this)#QueryBuilder] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  21. def ensuring(cond: Boolean, msg: => Any): (QueryBuilderFactory.this)#QueryBuilder
    Implicit
    This member is added by an implicit conversion from (QueryBuilderFactory.this)#QueryBuilder toEnsuring[(QueryBuilderFactory.this)#QueryBuilder] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  22. def ensuring(cond: Boolean): (QueryBuilderFactory.this)#QueryBuilder
    Implicit
    This member is added by an implicit conversion from (QueryBuilderFactory.this)#QueryBuilder toEnsuring[(QueryBuilderFactory.this)#QueryBuilder] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  23. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  24. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  25. def exhaust: (QueryBuilderFactory.this)#QueryBuilder

    Sets the flag to return all data returned by the query at once rather than splitting the results into batches.

    Sets the flag to return all data returned by the query at once rather than splitting the results into batches.

    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def ex(c: BSONCollection) =
      c.find(BSONDocument.empty).exhaust
  26. def explain(flag: Boolean = true): (QueryBuilderFactory.this)#QueryBuilder

    Toggles explain mode.

    Toggles explain mode.

    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def foo(coll: BSONCollection) = coll.find(BSONDocument.empty).explain()
  27. val explain: Boolean
  28. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  29. def formatted(fmtstr: String): String
    Implicit
    This member is added by an implicit conversion from (QueryBuilderFactory.this)#QueryBuilder toStringFormat[(QueryBuilderFactory.this)#QueryBuilder] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  30. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  31. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  32. def hint(h: (QueryBuilderFactory.this)#Hint): (QueryBuilderFactory.this)#QueryBuilder

    Sets the hint document (a document that declares the index MongoDB should use for this query).

    Sets the hint document (a document that declares the index MongoDB should use for this query).

    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def foo(coll: BSONCollection) = coll.find(BSONDocument.empty).
      hint(coll.hint(BSONDocument("foo" -> 1))) // sets the hint
  33. val hint: Option[(QueryBuilderFactory.this)#Hint]
  34. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  35. def max(document: P.Document): (QueryBuilderFactory.this)#QueryBuilder

    Sets the max document.

    Sets the max document.

    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def foo(coll: BSONCollection) = coll.find(BSONDocument.empty).
      max(BSONDocument("field" -> "maxValue"))
  36. val max: Option[P.Document]
  37. def maxScan(max: Double): (QueryBuilderFactory.this)#QueryBuilder

    Sets the maxScan flag.

    Sets the maxScan flag.

    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def foo(coll: BSONCollection) = coll.find(BSONDocument.empty).
      maxScan(1.23D)
  38. val maxScan: Option[Double]
  39. def maxTimeMs(milliseconds: Long): (QueryBuilderFactory.this)#QueryBuilder

    Adds maxTimeMs to query.

    Adds maxTimeMs to query.

    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def foo(coll: BSONCollection) = coll.find(BSONDocument.empty).
      maxTimeMs(1000L) // 1s
  40. val maxTimeMs: Option[Long]
  41. def min(document: P.Document): (QueryBuilderFactory.this)#QueryBuilder

    Sets the min document.

    Sets the min document.

    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def foo(coll: BSONCollection) = coll.find(BSONDocument.empty).
      min(BSONDocument("field" -> "minValue"))
  42. val min: Option[P.Document]
  43. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  44. def noCursorTimeout: (QueryBuilderFactory.this)#QueryBuilder

    Sets the noTimeout flag.

    Sets the noTimeout flag.

    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def acceptTimeout(c: BSONCollection) =
      c.find(BSONDocument.empty).noCursorTimeout
  45. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  46. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  47. def one[T](readPreference: ReadPreference)(implicit reader: P.Reader[T], ec: ExecutionContext): Future[Option[T]]

    Sends this query and gets a future Option[T] (alias for reactivemongo.api.Cursor.headOption).

    Sends this query and gets a future Option[T] (alias for reactivemongo.api.Cursor.headOption).

    import scala.concurrent.{ ExecutionContext, Future }
    
    import reactivemongo.api.ReadPreference
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def findUser(coll: BSONCollection, name: String)(
      implicit ec: ExecutionContext): Future[Option[BSONDocument]] =
      coll.find(BSONDocument("user" -> name)).
        one[BSONDocument](ReadPreference.primaryPreferred)
    T

    the results type

    readPreference

    The reactivemongo.api.ReadPreference for this query. If the ReadPreference implies that this query can be run on a secondary, the slaveOk flag will be set.

    reader

    the reader for the results type

  48. def one[T](implicit reader: P.Reader[T], ec: ExecutionContext): Future[Option[T]]

    Sends this query and gets a future Option[T] (alias for reactivemongo.api.Cursor.headOption) (using the default reactivemongo.api.ReadPreference).

    Sends this query and gets a future Option[T] (alias for reactivemongo.api.Cursor.headOption) (using the default reactivemongo.api.ReadPreference).

    import scala.concurrent.{ ExecutionContext, Future }
    
    import reactivemongo.api.bson.{ BSONDocument, Macros }
    import reactivemongo.api.bson.collection.BSONCollection
    
    case class User(name: String, pass: String)
    
    implicit val handler = Macros.reader[User]
    
    def findUser(coll: BSONCollection, name: String)(
      implicit ec: ExecutionContext): Future[Option[User]] =
      coll.find(BSONDocument("user" -> name)).one[User]
    T

    the results type

    reader

    the reader for the results type

  49. def projection[Pjn](p: Pjn)(implicit writer: P.Writer[Pjn]): (QueryBuilderFactory.this)#QueryBuilder

    Sets the projection specification to determine which fields to include in the returned documents.

    Sets the projection specification to determine which fields to include in the returned documents.

    import scala.concurrent.{ ExecutionContext, Future }
    
    import reactivemongo.api.Cursor
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def findAllWithProjection(coll: BSONCollection)(
      implicit ec: ExecutionContext): Future[List[BSONDocument]] =
      coll.find(BSONDocument.empty).
        projection(BSONDocument("age" -> 1)). // only consider 'age' field
        cursor[BSONDocument]().
        collect[List](
          maxDocs = 100,
          err = Cursor.FailOnError[List[BSONDocument]]())
    Pjn

    The type of the projection. An implicit Writer[Pjn] typeclass for handling it has to be in the scope.

  50. def projection(document: P.Document): (QueryBuilderFactory.this)#QueryBuilder

    Sets the projection specification to determine which fields to include in the returned documents.

  51. val projection: Option[P.Document]
  52. def readConcern(concern: ReadConcern): (QueryBuilderFactory.this)#QueryBuilder

    Sets the ReadConcern.

    Sets the ReadConcern.

    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def foo(coll: BSONCollection) = coll.find(BSONDocument.empty).
      readConcern(reactivemongo.api.ReadConcern.Local)
  53. val readConcern: ReadConcern
  54. def requireOne[T](readPreference: ReadPreference)(implicit reader: P.Reader[T], ec: ExecutionContext): Future[T]

    Sends this query and gets a future T (alias for reactivemongo.api.Cursor.head).

    Sends this query and gets a future T (alias for reactivemongo.api.Cursor.head).

    import scala.concurrent.{ ExecutionContext, Future }
    
    import reactivemongo.api.ReadPreference
    import reactivemongo.api.bson.{ BSONDocument, Macros }
    import reactivemongo.api.bson.collection.BSONCollection
    
    case class User(name: String, pass: String)
    
    implicit val handler = Macros.handler[User]
    
    def findUser(coll: BSONCollection, name: String)(
      implicit ec: ExecutionContext): Future[User] =
      coll.find(BSONDocument("user" -> name)).
        requireOne[User](ReadPreference.primaryPreferred)
    T

    the results type

    readPreference

    The reactivemongo.api.ReadPreference for this query. If the ReadPreference implies that this query can be run on a secondary, the slaveOk flag will be set.

    reader

    the reader for the results type

  55. def requireOne[T](implicit reader: P.Reader[T], ec: ExecutionContext): Future[T]

    Sends this query and gets a future T (alias for reactivemongo.api.Cursor.head) (using the default reactivemongo.api.ReadPreference).

    Sends this query and gets a future T (alias for reactivemongo.api.Cursor.head) (using the default reactivemongo.api.ReadPreference).

    import scala.concurrent.{ ExecutionContext, Future }
    
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def findUser(coll: BSONCollection, name: String)(
      implicit ec: ExecutionContext): Future[BSONDocument] =
      coll.find(BSONDocument("user" -> name)).requireOne[BSONDocument]
    T

    the results type

    reader

    the reader for the results type

  56. def returnKey(flag: Boolean = true): (QueryBuilderFactory.this)#QueryBuilder

    Sets the returnKey flag.

    Sets the returnKey flag.

    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def foo(coll: BSONCollection) = coll.find(BSONDocument.empty).returnKey()
  57. val returnKey: Boolean
  58. def showRecordId(flag: Boolean = true): (QueryBuilderFactory.this)#QueryBuilder

    Sets the showRecordId flag.

    Sets the showRecordId flag.

    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def foo(coll: BSONCollection) =
      coll.find(BSONDocument.empty).showRecordId()
  59. val showRecordId: Boolean
  60. def singleBatch(flag: Boolean = true): (QueryBuilderFactory.this)#QueryBuilder

    Sets the singleBatch flag.

    Sets the singleBatch flag.

    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def foo(coll: BSONCollection) = coll.find(BSONDocument.empty).
      singleBatch()
  61. val singleBatch: Boolean
  62. def skip(n: Int): (QueryBuilderFactory.this)#QueryBuilder

    Sets how many documents must be skipped at the beginning of the results.

    Sets how many documents must be skipped at the beginning of the results.

    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def skipTen(c: BSONCollection) =
      c.find(BSONDocument.empty).skip(10)
  63. val skip: Int
  64. def slaveOk: (QueryBuilderFactory.this)#QueryBuilder

    Allows querying of a replica slave (slaveOk).

    Allows querying of a replica slave (slaveOk).

    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def makeSlaveOk(c: BSONCollection) =
      c.find(BSONDocument.empty).slaveOk
  65. def snapshot(flag: Boolean = true): (QueryBuilderFactory.this)#QueryBuilder

    Toggles snapshot mode.

    Toggles snapshot mode.

    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def foo(coll: BSONCollection) = coll.find(BSONDocument.empty).snapshot()
  66. val snapshot: Boolean
  67. def sort(document: P.Document): (QueryBuilderFactory.this)#QueryBuilder

    Sets the sort specification for the ordering of the results.

    Sets the sort specification for the ordering of the results.

    import scala.concurrent.{ ExecutionContext, Future }
    
    import reactivemongo.api.Cursor
    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def findSortedVisible(coll: BSONCollection)(
      implicit ec: ExecutionContext): Future[List[BSONDocument]] =
      coll.find(BSONDocument("visible" -> true)).
        sort(BSONDocument("age" -> 1)). // sort per age
        cursor[BSONDocument]().
        collect[List](
          maxDocs = 100,
          err = Cursor.FailOnError[List[BSONDocument]]())
  68. val sort: Option[P.Document]
  69. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  70. def tailable: (QueryBuilderFactory.this)#QueryBuilder

    Makes the result cursor tailable.

    Makes the result cursor tailable.

    import reactivemongo.api.bson.BSONDocument
    import reactivemongo.api.bson.collection.BSONCollection
    
    def ensureTailable(c: BSONCollection) =
      c.find(BSONDocument.empty).tailable
  71. def toString(): String
    Definition Classes
    AnyRef → Any
  72. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  73. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  74. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Deprecated Value Members

  1. def [B](y: B): ((QueryBuilderFactory.this)#QueryBuilder, B)
    Implicit
    This member is added by an implicit conversion from (QueryBuilderFactory.this)#QueryBuilder toArrowAssoc[(QueryBuilderFactory.this)#QueryBuilder] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @deprecated
    Deprecated

    (Since version 2.13.0) Use -> instead. If you still wish to display it as one character, consider using a font with programming ligatures such as Fira Code.

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd from(QueryBuilderFactory.this)#QueryBuilder to any2stringadd[(QueryBuilderFactory.this)#QueryBuilder]

Inherited by implicit conversion StringFormat from(QueryBuilderFactory.this)#QueryBuilder to StringFormat[(QueryBuilderFactory.this)#QueryBuilder]

Inherited by implicit conversion Ensuring from(QueryBuilderFactory.this)#QueryBuilder to Ensuring[(QueryBuilderFactory.this)#QueryBuilder]

Inherited by implicit conversion ArrowAssoc from(QueryBuilderFactory.this)#QueryBuilder to ArrowAssoc[(QueryBuilderFactory.this)#QueryBuilder]

Ungrouped