reactivemongo.api.collections.QueryBuilderFactory
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
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
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)
the upper limit on the number of documents to retrieve per batch (0 for unspecified)
Sets the collation
document.
Sets the collation
document.
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)
the optional collation to use for the find command (default: None
) {@since MongoDB 3.4}
the optional collation to use for the find command (default: None
) {@since MongoDB 3.4}
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] }
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")
the query comment
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]]())
the results type
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.
the reader for the results type
the cursor options
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
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()
the explain flag
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
the index to “hint” or force MongoDB to use when performing the query.
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"))
the optional exclusive upper bound for a specific index (default: None
)
Adds maxAwaitTimeMs to query.
Adds maxAwaitTimeMs to query.
import reactivemongo.api.bson.BSONDocument import reactivemongo.api.bson.collection.BSONCollection def foo(coll: BSONCollection) = coll.find(BSONDocument.empty).maxAwaitTimeMs(1000L) // 1s
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)
this option specifies a maximum number of documents or index keys the query plan will scan.
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
the maximum execution time
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"))
the optional exclusive lower bound for a specific index (default: None
)
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
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)
the results type
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.
the reader for the results type
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, BSONDocumentHandler, Macros } import reactivemongo.api.bson.collection.BSONCollection case class User(name: String, pass: String) implicit val handler: BSONDocumentHandler[User] = Macros.handler[User] def findUser(coll: BSONCollection, name: String)( implicit ec: ExecutionContext): Future[Option[User]] = coll.find(BSONDocument("user" -> name)).one[User]
the results type
the reader for the results type
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]]())
The type of the projection. An implicit Writer[Pjn]
typeclass for handling it has to be in the scope.
Sets the projection specification to determine which fields to include in the returned documents.
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)
the read concern {@since MongoDB 3.6}
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, BSONDocumentHandler, Macros } import reactivemongo.api.bson.collection.BSONCollection case class User(name: String, pass: String) implicit val handler: BSONDocumentHandler[User] = Macros.handler[User] def findUser(coll: BSONCollection, name: String)( implicit ec: ExecutionContext): Future[User] = coll.find(BSONDocument("user" -> name)). requireOne[User](ReadPreference.primaryPreferred)
the results type
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.
the reader for the results type
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]
the results type
the reader for the results type
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()
if this flag is true, returns only the index keys in the resulting documents
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()
the flags to determines whether to return the record identifier for each document
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()
the flag to determines whether to close the cursor after the first batch (default: false
)
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)
the number of documents to skip.
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
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()
the snapshot flag
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]]())
the optional sort specification
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
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, orone
if you want to retrieve just one document.