reactivemongo.api.collections

GenericQueryBuilder

trait GenericQueryBuilder[P <: SerializationPack] extends QueryOps

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.

import scala.concurrent.{ ExecutionContext, Future }

import reactivemongo.api.bson.BSONDocument
import reactivemongo.api.bson.collection.BSONCollection

def firstFirst(coll: BSONCollection)(
  implicit ec: ExecutionContext): Future[Option[BSONDocument]] = {
  val queryBuilder = coll.find(BSONDocument.empty)
  queryBuilder.one[BSONDocument]
}
Annotations
@deprecated
Deprecated

(Since version 0.16.0) Internal: will be made private

Linear Supertypes
QueryOps, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. GenericQueryBuilder
  2. QueryOps
  3. AnyRef
  4. Any
Implicitly
  1. by any2stringadd
  2. by any2stringfmt
  3. by any2ArrowAssoc
  4. by any2Ensuring
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. abstract type Self <: GenericQueryBuilder[pack.type]

    Definition Classes
    GenericQueryBuilderQueryOps

Abstract Value Members

  1. abstract def commentString: Option[String]

  2. abstract def explainFlag: Boolean

  3. abstract def failoverStrategy: FailoverStrategy

    Annotations
    @deprecatedName( Symbol("failover") )
  4. abstract def hintOption: Option[P.Document]

  5. abstract def maxTimeMsOption: Option[Long]

  6. abstract def options: QueryOpts

  7. abstract val pack: P

  8. abstract def projectionOption: Option[P.Document]

  9. abstract def queryOption: Option[P.Document]

  10. abstract def snapshotFlag: Boolean

  11. abstract def sortOption: Option[P.Document]

  12. abstract def version: MongoWireVersion

    Attributes
    protected
  13. abstract def copy(queryOption: Option[P.Document] = queryOption, sortOption: Option[P.Document] = sortOption, projectionOption: Option[P.Document] = projectionOption, hintOption: Option[P.Document] = hintOption, explainFlag: Boolean = explainFlag, snapshotFlag: Boolean = snapshotFlag, commentString: Option[String] = commentString, options: QueryOpts = options, failoverStrategy: FailoverStrategy = failoverStrategy, maxTimeMsOption: Option[Long] = maxTimeMsOption): Self

    Annotations
    @deprecated
    Deprecated

    (Since version 0.16.0) Internal: will be made private

Concrete Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. def +(other: String): String

    Implicit information
    This member is added by an implicit conversion from GenericQueryBuilder[P] to StringAdd performed by method any2stringadd in scala.Predef.
    Definition Classes
    StringAdd
  5. def ->[B](y: B): (GenericQueryBuilder[P], B)

    Implicit information
    This member is added by an implicit conversion from GenericQueryBuilder[P] to ArrowAssoc[GenericQueryBuilder[P]] performed by method any2ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  6. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  7. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  8. def allowPartialResults: Self

    For queries against a sharded collection, returns partial results from the mongos if some shards are unavailable instead of throwing an error.

  9. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  10. def awaitData: Self

    Toggles AwaitData: Block a little while waiting for more data instead of returning immediately if no data.

    Toggles AwaitData: Block a little while waiting for more data instead of returning immediately if no data. Use along with TailableCursor.

    Definition Classes
    GenericQueryBuilderQueryOps
  11. def batchSize(n: Int): Self

    Sets an upper limit on the number of documents to retrieve per batch.

    Sets an upper limit on the number of documents to retrieve per batch. Defaults to 0 (meaning no upper limit - MongoDB decides).

    Definition Classes
    GenericQueryBuilderQueryOps
  12. lazy val builder: Builder[pack.type]

  13. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  14. def collation(collation: Collation): Self

    Sets the collation document.

    Sets the collation document.

    Since

    MongoDB 3.4

  15. def collation: Option[Collation]

    The optional collation to use for the find command (default: None).

    The optional collation to use for the find command (default: None).

    Annotations
    @inline()
    Since

    MongoDB 3.4

  16. def collection: Collection

  17. def comment(message: String): Self

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

  18. def cursor[T](readPreference: ReadPreference = readPreference, isMongo26WriteOp: Boolean = false)(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

  19. def ensuring(cond: (GenericQueryBuilder[P]) ⇒ Boolean, msg: ⇒ Any): GenericQueryBuilder[P]

    Implicit information
    This member is added by an implicit conversion from GenericQueryBuilder[P] to Ensuring[GenericQueryBuilder[P]] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  20. def ensuring(cond: (GenericQueryBuilder[P]) ⇒ Boolean): GenericQueryBuilder[P]

    Implicit information
    This member is added by an implicit conversion from GenericQueryBuilder[P] to Ensuring[GenericQueryBuilder[P]] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  21. def ensuring(cond: Boolean, msg: ⇒ Any): GenericQueryBuilder[P]

    Implicit information
    This member is added by an implicit conversion from GenericQueryBuilder[P] to Ensuring[GenericQueryBuilder[P]] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  22. def ensuring(cond: Boolean): GenericQueryBuilder[P]

    Implicit information
    This member is added by an implicit conversion from GenericQueryBuilder[P] to Ensuring[GenericQueryBuilder[P]] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  23. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  24. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  25. def exhaust: Self

    Toggles Exhaust

    Toggles Exhaust

    Definition Classes
    GenericQueryBuilderQueryOps
  26. def explain(flag: Boolean = true): Self

    Toggles explain mode.

  27. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  28. def formatted(fmtstr: String): String

    Implicit information
    This member is added by an implicit conversion from GenericQueryBuilder[P] to StringFormat performed by method any2stringfmt in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  29. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  30. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  31. def hint(document: P.Document): Self

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

  32. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  33. def max(document: P.Document): Self

    Sets the max document.

  34. def max: Option[P.Document]

    The optional exclusive upper bound for a specific index (default: None).

    The optional exclusive upper bound for a specific index (default: None).

    Annotations
    @inline()
  35. def maxScan(max: Double): Self

    Sets the maxScan flag.

  36. def maxScan: Option[Double]

    This option specifies a maximum number of documents or index keys the query plan will scan.

    This option specifies a maximum number of documents or index keys the query plan will scan.

    Annotations
    @inline()
  37. def maxTimeMs(p: Long): Self

    Adds maxTimeMs to query

  38. def min(document: P.Document): Self

    Sets the min document.

  39. def min: Option[P.Document]

    The optional exclusive lower bound for a specific index (default: None).

    The optional exclusive lower bound for a specific index (default: None).

    Annotations
    @inline()
  40. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  41. def noCursorTimeout: Self

    Toggles NoCursorTimeout: The cursor will not expire automatically

    Toggles NoCursorTimeout: The cursor will not expire automatically

    Definition Classes
    GenericQueryBuilderQueryOps
  42. final def notify(): Unit

    Definition Classes
    AnyRef
  43. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  44. 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

  45. 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

  46. def oplogReplay: Self

    Toggles OplogReplay

    Toggles OplogReplay

    Definition Classes
    GenericQueryBuilderQueryOps
  47. def options(options: QueryOpts): Self

  48. def projection(p: P.Document): Self

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

  49. def projection[Pjn](p: Pjn)(implicit writer: P.Writer[Pjn]): Self

    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 readConcern(concern: ReadConcern): Self

    Sets the ReadConcern.

  51. def readConcern: ReadConcern

    The read concern

    The read concern

    Annotations
    @inline()
    Since

    MongoDB 3.6

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

  53. 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

  54. def returnKey(flag: Boolean): Self

    Sets the returnKey flag.

  55. def returnKey: Boolean

    If this flag is true, returns only the index keys in the resulting documents.

    If this flag is true, returns only the index keys in the resulting documents.

    Annotations
    @inline()
  56. def showRecordId(flag: Boolean): Self

    Sets the showRecordId flag.

  57. def showRecordId: Boolean

    The flags to determines whether to return the record identifier for each document.

    The flags to determines whether to return the record identifier for each document.

    Annotations
    @inline()
  58. def singleBatch(flag: Boolean): Self

    Sets the singleBatch flag.

  59. def singleBatch: Boolean

    The flag to determines whether to close the cursor after the first batch (default: false)

    The flag to determines whether to close the cursor after the first batch (default: false)

    Annotations
    @inline()
  60. def skip(n: Int): Self

    Sets the number of documents to skip at the beginning of the results.

    Sets the number of documents to skip at the beginning of the results.

    Definition Classes
    GenericQueryBuilderQueryOps
    See also

    QueryOpts.skipN

  61. def slaveOk: Self

    Toggles SlaveOk: The query is might be run on a secondary.

    Toggles SlaveOk: The query is might be run on a secondary.

    Definition Classes
    GenericQueryBuilderQueryOps
  62. def snapshot(flag: Boolean = true): Self

    Toggles snapshot mode.

  63. def sort(document: P.Document): Self

    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]]())
  64. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  65. def tailable: Self

    Toggles TailableCursor: Makes the cursor not to close after all the data is consumed.

    Toggles TailableCursor: Makes the cursor not to close after all the data is consumed.

    Definition Classes
    GenericQueryBuilderQueryOps
  66. def toString(): String

    Definition Classes
    AnyRef → Any
  67. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  68. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  69. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  70. def [B](y: B): (GenericQueryBuilder[P], B)

    Implicit information
    This member is added by an implicit conversion from GenericQueryBuilder[P] to ArrowAssoc[GenericQueryBuilder[P]] performed by method any2ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Shadowed Implicit Value Members

  1. val self: Any

    Implicit information
    This member is added by an implicit conversion from GenericQueryBuilder[P] to StringAdd performed by method any2stringadd in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (genericQueryBuilder: StringAdd).self
    Definition Classes
    StringAdd
  2. val self: Any

    Implicit information
    This member is added by an implicit conversion from GenericQueryBuilder[P] to StringFormat performed by method any2stringfmt in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (genericQueryBuilder: StringFormat).self
    Definition Classes
    StringFormat

Deprecated Value Members

  1. def filter(predicate: P.Document): Self

    Sets the query predicate; If unspecified, then all documents in the collection will match the predicate.

    Sets the query predicate; If unspecified, then all documents in the collection will match the predicate.

    Annotations
    @deprecated
    Deprecated

    (Since version 0.19.4) Specify the filter predicate using collection.find(..)

  2. def filter[Qry](predicate: Qry)(implicit writer: P.Writer[Qry]): Self

    Sets the query predicate; If unspecified, then all documents in the collection will match the predicate.

    Sets the query predicate; If unspecified, then all documents in the collection will match the predicate.

    Qry

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

    Annotations
    @deprecated
    Deprecated

    (Since version 0.19.4) Specify the filter predicate using collection.find(..)

  3. def partial: Self

    Toggles Partial: The response can be partial - if a shard is down, no error will be thrown.

    Toggles Partial: The response can be partial - if a shard is down, no error will be thrown.

    Definition Classes
    GenericQueryBuilderQueryOps
    Annotations
    @deprecated
    Deprecated

    (Since version 0.19.8) Use allowPartialResults

  4. def query(selector: P.Document): Self

    Annotations
    @deprecated
    Deprecated

    (Since version 0.18.2) Use filter

  5. def query[Qry](selector: Qry)(implicit writer: P.Writer[Qry]): Self

    Annotations
    @deprecated
    Deprecated

    (Since version 0.18.2) Use filter

  6. def readPreference: ReadPreference

    The default ReadPreference

    The default ReadPreference

    Annotations
    @deprecated @inline()
    Deprecated

    (Since version 0.16.0) Internal: will be made private

  7. def updateOptions(update: (QueryOpts) ⇒ QueryOpts): Self

    Annotations
    @deprecated
    Deprecated

    (Since version 0.12.4) Use options or the separate query ops

  8. def x: GenericQueryBuilder[P]

    Implicit information
    This member is added by an implicit conversion from GenericQueryBuilder[P] to ArrowAssoc[GenericQueryBuilder[P]] performed by method any2ArrowAssoc in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (genericQueryBuilder: ArrowAssoc[GenericQueryBuilder[P]]).x
    Definition Classes
    ArrowAssoc
    Annotations
    @deprecated
    Deprecated

    (Since version 2.10.0) Use leftOfArrow instead

  9. def x: GenericQueryBuilder[P]

    Implicit information
    This member is added by an implicit conversion from GenericQueryBuilder[P] to Ensuring[GenericQueryBuilder[P]] performed by method any2Ensuring in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (genericQueryBuilder: Ensuring[GenericQueryBuilder[P]]).x
    Definition Classes
    Ensuring
    Annotations
    @deprecated
    Deprecated

    (Since version 2.10.0) Use resultOfEnsuring instead

Inherited from QueryOps

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd from GenericQueryBuilder[P] to StringAdd

Inherited by implicit conversion any2stringfmt from GenericQueryBuilder[P] to StringFormat

Inherited by implicit conversion any2ArrowAssoc from GenericQueryBuilder[P] to ArrowAssoc[GenericQueryBuilder[P]]

Inherited by implicit conversion any2Ensuring from GenericQueryBuilder[P] to Ensuring[GenericQueryBuilder[P]]

Ungrouped