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
- Alphabetic
- By Inheritance
- GenericQueryBuilder
- QueryOps
- AnyRef
- Any
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- Protected
Type Members
- abstract type Self <: GenericQueryBuilder[pack.type]
- Definition Classes
- GenericQueryBuilder → QueryOps
Abstract Value Members
- abstract def commentString: Option[String]
- abstract def explainFlag: Boolean
- abstract def failoverStrategy: FailoverStrategy
- Annotations
- @deprecatedName(Symbol("failover"))
- abstract def hintOption: Option[P.Document]
- abstract def maxTimeMsOption: Option[Long]
- abstract def options: QueryOpts
- abstract val pack: P
- abstract def projectionOption: Option[P.Document]
- abstract def queryOption: Option[P.Document]
- abstract def snapshotFlag: Boolean
- abstract def sortOption: Option[P.Document]
- abstract def version: MongoWireVersion
- Attributes
- protected
- 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
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##(): Int
- Definition Classes
- AnyRef → Any
- def +(other: String): String
- Implicit
- This member is added by an implicit conversion from GenericQueryBuilder[P] toany2stringadd[GenericQueryBuilder[P]] performed by method any2stringadd in scala.Predef.
- Definition Classes
- any2stringadd
- def ->[B](y: B): (GenericQueryBuilder[P], B)
- Implicit
- This member is added by an implicit conversion from GenericQueryBuilder[P] toArrowAssoc[GenericQueryBuilder[P]] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc
- Annotations
- @inline()
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- 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.
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- 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
- GenericQueryBuilder → QueryOps
- 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
- GenericQueryBuilder → QueryOps
- lazy val builder: Builder[pack.type]
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- def collation(collation: Collation): Self
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)
- 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
- def collection: Collection
- def comment(message: String): Self
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")
- 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
- def ensuring(cond: (GenericQueryBuilder[P]) => Boolean, msg: => Any): GenericQueryBuilder[P]
- Implicit
- This member is added by an implicit conversion from GenericQueryBuilder[P] toEnsuring[GenericQueryBuilder[P]] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
- def ensuring(cond: (GenericQueryBuilder[P]) => Boolean): GenericQueryBuilder[P]
- Implicit
- This member is added by an implicit conversion from GenericQueryBuilder[P] toEnsuring[GenericQueryBuilder[P]] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
- def ensuring(cond: Boolean, msg: => Any): GenericQueryBuilder[P]
- Implicit
- This member is added by an implicit conversion from GenericQueryBuilder[P] toEnsuring[GenericQueryBuilder[P]] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
- def ensuring(cond: Boolean): GenericQueryBuilder[P]
- Implicit
- This member is added by an implicit conversion from GenericQueryBuilder[P] toEnsuring[GenericQueryBuilder[P]] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def exhaust: Self
Toggles Exhaust
Toggles Exhaust
- Definition Classes
- GenericQueryBuilder → QueryOps
- def explain(flag: Boolean = true): Self
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()
- def formatted(fmtstr: String): String
- Implicit
- This member is added by an implicit conversion from GenericQueryBuilder[P] toStringFormat[GenericQueryBuilder[P]] performed by method StringFormat in scala.Predef.
- Definition Classes
- StringFormat
- Annotations
- @inline()
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def hint(document: P.Document): Self
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(BSONDocument("hint" -> 1)) // sets the hint
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def max(document: P.Document): Self
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"))
- 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()
- def maxScan(max: Double): Self
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)
- 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()
- def maxTimeMs(p: Long): Self
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 */)
- def min(document: P.Document): Self
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"))
- 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()
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def noCursorTimeout: Self
Toggles NoCursorTimeout: The cursor will not expire automatically
Toggles NoCursorTimeout: The cursor will not expire automatically
- Definition Classes
- GenericQueryBuilder → QueryOps
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- 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
- 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
- def oplogReplay: Self
Toggles OplogReplay
Toggles OplogReplay
- Definition Classes
- GenericQueryBuilder → QueryOps
- def options(options: QueryOpts): Self
- def projection(p: P.Document): Self
Sets the projection specification to determine which fields to include in the returned documents.
- 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.
- def readConcern(concern: ReadConcern): Self
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)
- def readConcern: ReadConcern
The read concern
The read concern
- Annotations
- @inline()
- Since
MongoDB 3.6
- 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
- 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
- def returnKey(flag: Boolean = true): Self
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()
- 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()
- def showRecordId(flag: Boolean = true): Self
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()
- 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()
- def singleBatch(flag: Boolean = true): Self
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()
- 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()
- 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
- GenericQueryBuilder → QueryOps
- See also
- 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
- GenericQueryBuilder → QueryOps
- def snapshot(flag: Boolean = true): Self
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()
- 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]]())
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- 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
- GenericQueryBuilder → QueryOps
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- 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()
Deprecated Value Members
- 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(..)
- 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(..)
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated @deprecated
- Deprecated
(Since version ) see corresponding Javadoc for more information.
- 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
- GenericQueryBuilder → QueryOps
- Annotations
- @deprecated
- Deprecated
(Since version 0.19.8) Use
allowPartialResults
- def query(selector: P.Document): Self
- Annotations
- @deprecated
- Deprecated
(Since version 0.18.2) Use
filter
- def query[Qry](selector: Qry)(implicit writer: P.Writer[Qry]): Self
- Annotations
- @deprecated
- Deprecated
(Since version 0.18.2) Use
filter
- def readPreference: ReadPreference
The default ReadPreference
The default ReadPreference
- Annotations
- @deprecated @inline()
- Deprecated
(Since version 0.16.0) Internal: will be made private
- def updateOptions(update: (QueryOpts) => QueryOpts): Self
- Annotations
- @deprecated
- Deprecated
(Since version 0.12.4) Use
options
or the separate query ops
- def →[B](y: B): (GenericQueryBuilder[P], B)
- Implicit
- This member is added by an implicit conversion from GenericQueryBuilder[P] toArrowAssoc[GenericQueryBuilder[P]] 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.