For queries against a sharded collection, returns partial results from the mongos if some shards are unavailable instead of throwing an error.
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
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
).
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.
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")
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.
Toggles explain mode.
import reactivemongo.api.bson.BSONDocument import reactivemongo.api.bson.collection.BSONCollection def foo(coll: BSONCollection) = coll.find(BSONDocument.empty).explain()
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
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
).
The optional exclusive upper bound for a specific index (default: None
).
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.
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 */)
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
).
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.
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.
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
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.
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.
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.
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
)
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.
Toggles snapshot mode.
import reactivemongo.api.bson.BSONDocument import reactivemongo.api.bson.collection.BSONCollection def foo(coll: BSONCollection) = coll.find(BSONDocument.empty).snapshot()
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.
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
(Since version 0.16.0) Useless, will be remove