(Since version 0.16.0) Internal: will be made private
For queries against a sharded collection, returns partial results from the mongos if some shards are unavailable instead of throwing an error.
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.
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).
Sets the collation
document.
Sets the collation
document.
MongoDB 3.4
The optional collation to use for the find command (default: None
).
The optional collation to use for the find command (default: None
).
MongoDB 3.4
Adds a comment to this query, that may appear in the MongoDB logs.
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
Toggles Exhaust
Toggles Exhaust
Toggles explain mode.
Sets the hint document (a document that declares the index MongoDB should use for this query).
Sets the max
document.
The optional exclusive upper bound for a specific index (default: None
).
The optional exclusive upper bound for a specific index (default: None
).
Sets the maxScan
flag.
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.
Adds maxTimeMs to query
Sets the min
document.
The optional exclusive lower bound for a specific index (default: None
).
The optional exclusive lower bound for a specific index (default: None
).
Toggles NoCursorTimeout: The cursor will not expire automatically
Toggles NoCursorTimeout: The cursor will not expire automatically
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, 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]
the results type
the reader for the results type
Toggles OplogReplay
Toggles OplogReplay
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.
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 ReadConcern.
The read concern
The read concern
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, 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)
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.
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.
Sets the showRecordId
flag.
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.
Sets the singleBatch
flag.
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
)
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.
Toggles SlaveOk: The query is might be run on a secondary.
Toggles SlaveOk: The query is might be run on a secondary.
Toggles snapshot mode.
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]]())
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.
(genericQueryBuilder: StringAdd).self
(genericQueryBuilder: StringFormat).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.
(Since version 0.19.4) Specify the filter predicate using collection.find(..)
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.
The type of the query. An implicit Writer[Qry]
typeclass for handling it has to be in the scope.
(Since version 0.19.4) Specify the filter predicate using collection.find(..)
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.
(Since version 0.19.8) Use allowPartialResults
(Since version 0.18.2) Use filter
(Since version 0.18.2) Use filter
The default ReadPreference
The default ReadPreference
(Since version 0.16.0) Internal: will be made private
(Since version 0.12.4) Use options
or the separate query ops
(genericQueryBuilder: ArrowAssoc[GenericQueryBuilder[P]]).x
(Since version 2.10.0) Use leftOfArrow
instead
(genericQueryBuilder: Ensuring[GenericQueryBuilder[P]]).x
(Since version 2.10.0) Use resultOfEnsuring
instead
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.(Since version 0.16.0) Internal: will be made private