final class QueryBuilder extends AnyRef
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.
- Alphabetic
- By Inheritance
- QueryBuilder
- AnyRef
- Any
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- All
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 (QueryBuilderFactory.this)#QueryBuilder to any2stringadd[(QueryBuilderFactory.this)#QueryBuilder] performed by method any2stringadd in scala.Predef.
- Definition Classes
- any2stringadd
-
def
->[B](y: B): ((QueryBuilderFactory.this)#QueryBuilder, B)
- Implicit
- This member is added by an implicit conversion from (QueryBuilderFactory.this)#QueryBuilder to ArrowAssoc[(QueryBuilderFactory.this)#QueryBuilder] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc
- Annotations
- @inline()
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
allowPartialResults: (QueryBuilderFactory.this)#QueryBuilder
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
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
awaitData: (QueryBuilderFactory.this)#QueryBuilder
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
-
def
batchSize(n: Int): (QueryBuilderFactory.this)#QueryBuilder
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)
- val batchSize: Int
- lazy val builder: Builder[(QueryBuilderFactory.this)#pack.type]
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
collation(collation: Collation): (QueryBuilderFactory.this)#QueryBuilder
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)
- val collation: Option[Collation]
-
def
comment(message: String): (QueryBuilderFactory.this)#QueryBuilder
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")
- val comment: Option[String]
-
def
cursor[T](readPreference: ReadPreference = readPreference)(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
- val cursorOptions: CursorOptions
-
def
ensuring(cond: ((QueryBuilderFactory.this)#QueryBuilder) ⇒ Boolean, msg: ⇒ Any): (QueryBuilderFactory.this)#QueryBuilder
- Implicit
- This member is added by an implicit conversion from (QueryBuilderFactory.this)#QueryBuilder to Ensuring[(QueryBuilderFactory.this)#QueryBuilder] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: ((QueryBuilderFactory.this)#QueryBuilder) ⇒ Boolean): (QueryBuilderFactory.this)#QueryBuilder
- Implicit
- This member is added by an implicit conversion from (QueryBuilderFactory.this)#QueryBuilder to Ensuring[(QueryBuilderFactory.this)#QueryBuilder] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: Boolean, msg: ⇒ Any): (QueryBuilderFactory.this)#QueryBuilder
- Implicit
- This member is added by an implicit conversion from (QueryBuilderFactory.this)#QueryBuilder to Ensuring[(QueryBuilderFactory.this)#QueryBuilder] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
def
ensuring(cond: Boolean): (QueryBuilderFactory.this)#QueryBuilder
- Implicit
- This member is added by an implicit conversion from (QueryBuilderFactory.this)#QueryBuilder to Ensuring[(QueryBuilderFactory.this)#QueryBuilder] performed by method Ensuring in scala.Predef.
- Definition Classes
- Ensuring
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
exhaust: (QueryBuilderFactory.this)#QueryBuilder
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
-
def
explain(flag: Boolean = true): (QueryBuilderFactory.this)#QueryBuilder
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()
- val explain: Boolean
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
formatted(fmtstr: String): String
- Implicit
- This member is added by an implicit conversion from (QueryBuilderFactory.this)#QueryBuilder to StringFormat[(QueryBuilderFactory.this)#QueryBuilder] performed by method StringFormat in scala.Predef.
- Definition Classes
- StringFormat
- Annotations
- @inline()
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hint(h: (QueryBuilderFactory.this)#Hint): (QueryBuilderFactory.this)#QueryBuilder
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
- val hint: Option[(QueryBuilderFactory.this)#Hint]
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
max(document: P.Document): (QueryBuilderFactory.this)#QueryBuilder
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"))
- val max: Option[P.Document]
-
def
maxAwaitTimeMs(milliseconds: Long): (QueryBuilderFactory.this)#QueryBuilder
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
- val maxAwaitTimeMs: Option[Long]
-
def
maxScan(max: Double): (QueryBuilderFactory.this)#QueryBuilder
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)
- val maxScan: Option[Double]
-
def
maxTimeMs(milliseconds: Long): (QueryBuilderFactory.this)#QueryBuilder
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
- val maxTimeMs: Option[Long]
-
def
min(document: P.Document): (QueryBuilderFactory.this)#QueryBuilder
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"))
- val min: Option[P.Document]
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
noCursorTimeout: (QueryBuilderFactory.this)#QueryBuilder
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
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
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
projection[Pjn](p: Pjn)(implicit writer: P.Writer[Pjn]): (QueryBuilderFactory.this)#QueryBuilder
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
projection(document: P.Document): (QueryBuilderFactory.this)#QueryBuilder
Sets the projection specification to determine which fields to include in the returned documents.
- val projection: Option[P.Document]
-
def
readConcern(concern: ReadConcern): (QueryBuilderFactory.this)#QueryBuilder
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)
- val readConcern: ReadConcern
-
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): (QueryBuilderFactory.this)#QueryBuilder
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()
- val returnKey: Boolean
-
def
showRecordId(flag: Boolean = true): (QueryBuilderFactory.this)#QueryBuilder
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()
- val showRecordId: Boolean
-
def
singleBatch(flag: Boolean = true): (QueryBuilderFactory.this)#QueryBuilder
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()
- val singleBatch: Boolean
-
def
skip(n: Int): (QueryBuilderFactory.this)#QueryBuilder
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)
- val skip: Int
-
def
slaveOk: (QueryBuilderFactory.this)#QueryBuilder
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
-
def
snapshot(flag: Boolean = true): (QueryBuilderFactory.this)#QueryBuilder
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()
- val snapshot: Boolean
-
def
sort(document: P.Document): (QueryBuilderFactory.this)#QueryBuilder
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]]())
- val sort: Option[P.Document]
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
tailable: (QueryBuilderFactory.this)#QueryBuilder
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
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
→[B](y: B): ((QueryBuilderFactory.this)#QueryBuilder, B)
- Implicit
- This member is added by an implicit conversion from (QueryBuilderFactory.this)#QueryBuilder to ArrowAssoc[(QueryBuilderFactory.this)#QueryBuilder] performed by method ArrowAssoc in scala.Predef.
- Definition Classes
- ArrowAssoc