reactivemongo.api

Members list

Concise view

Type members

Classlikes

final class AsyncDriver(val config: Option[Config], val classLoader: Option[ClassLoader])

The asynchronous driver (see MongoConnection).

The asynchronous driver (see MongoConnection).

import scala.concurrent.Future
import reactivemongo.api.{ AsyncDriver, MongoConnection }

val driver = AsyncDriver()
val connection: Future[MongoConnection] =
 driver.connect("mongodb://node:27017")

Attributes

classLoader

a classloader used to load the actor system

config

a custom configuration (otherwise the default options are used)

Companion:
object
Graph
Supertypes
class Object
trait Matchable
class Any

The driver factory

The driver factory

Attributes

Companion:
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
sealed trait AuthenticationMode

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Change stream utilities.

Change stream utilities.

import scala.concurrent.{ ExecutionContext, Future }

import reactivemongo.api.ChangeStreams.FullDocumentStrategy

import reactivemongo.api.bson.BSONDocument
import reactivemongo.api.bson.collection.BSONCollection

def peekNext(
 coll: BSONCollection,
 strategy: FullDocumentStrategy)(
 implicit ec: ExecutionContext): Future[Option[BSONDocument]] =
 coll.watch[BSONDocument](fullDocumentStrategy = Some(strategy)).
   cursor.headOption

def doIt(coll: BSONCollection)(
 implicit ec: ExecutionContext): Future[Unit] = for {
   _ <- peekNext(coll, FullDocumentStrategy.Default)
   _ <- peekNext(coll, FullDocumentStrategy.UpdateLookup)
 } yield ()

Attributes

See also:
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
final class Collation

Represents a collection, view, index or operation specific collation.

Represents a collection, view, index or operation specific collation.

import reactivemongo.api.Collation

val collation = Collation(
 locale = "en-US",
 caseLevel = None,
 caseFirst = None,
 strength = Some(Collation.PrimaryStrength),
 numericOrdering = None,
 alternate = None,
 maxVariable = None,
 backwards = None)

Attributes

Companion:
object
Graph
Supertypes
class Object
trait Matchable
class Any
object Collation

Collation utilities.

Collation utilities.

Attributes

Companion:
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Basic information resolved for a MongoDB Collection, resolved from a reactivemongo.api.DB.

Basic information resolved for a MongoDB Collection, resolved from a reactivemongo.api.DB.

For collection operations, you should consider the generic API (reactivemongo.api.collections.GenericCollection).

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

A Producer of Collection implementation.

A Producer of Collection implementation.

This is used to get an implementation implicitly when getting a reference of a Collection.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
final class CollectionStats

Various information about a collection.

Various information about a collection.

Attributes

averageObjectSize

The average object size in bytes (or in bytes / scale, if any).

capped

States if this collection is capped.

count

The number of documents in this collection.

indexSizes

Size of specific indexes in bytes.

lastExtentSize

Size of the most recently created extent (only for mmapv1 storage engine).

max

The maximum number of documents of this collection, if capped.

maxSize

The maximum size in bytes (or in bytes / scale, if any) of this collection, if capped.

nindexes

Number of indexes.

ns

The fully qualified collection name.

numExtents

Number of extents (contiguously allocated chunks of datafile space, only for mmapv1 storage engine).

paddingFactor

Padding can speed up updates if documents grow (only for mmapv1 storage engine).

size

The size in bytes (or in bytes / scale, if any).

storageSize

Preallocated space for the collection.

systemFlags

System flags.

userFlags

User flags.

Graph
Supertypes
class Object
trait Matchable
class Any
trait Cursor[T]

Cursor over results from MongoDB.

Cursor over results from MongoDB.

import scala.concurrent.{ ExecutionContext, Future }

import reactivemongo.api.Cursor
import reactivemongo.api.bson.{ BSONDocument, BSONDocumentReader, Macros }
import reactivemongo.api.bson.collection.BSONCollection

case class User(name: String, pass: String)

implicit val reader: BSONDocumentReader[User] = Macros.reader[User]

def findUsers(coll: BSONCollection)(
 implicit ec: ExecutionContext): Future[List[User]] =
 coll.find(BSONDocument("enabled" -> true)).
   cursor[User](). // obtain cursor for User results
   collect[List](
     maxDocs = 10,
     err = Cursor.FailOnError[List[User]]())

Attributes

T

the type parsed from each result document

Companion:
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Cursor

Cursor companion object

Cursor companion object

Attributes

Companion:
trait
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Cursor.type
trait CursorFlattener[C <: (Cursor)]

Flattening strategy for cursor.

Flattening strategy for cursor.

import scala.concurrent.Future

import reactivemongo.api.{ Cursor, CursorFlattener }

trait FooCursor[T] extends Cursor[T] { def foo: String }

def flatFoo[T](future: Future[FooCursor[T]])(implicit cf: CursorFlattener[FooCursor]): FooCursor[T] = Cursor.flatten(future)

Attributes

Companion:
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Flatteners helper

Flatteners helper

Attributes

Companion:
trait
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
trait CursorOps[T]

Internal cursor operations.

Internal cursor operations.

Attributes

Companion:
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
Self type
object CursorOps

Attributes

Companion:
trait
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
final class CursorOptions extends AnyVal

Attributes

flags

the flags representing the current options

import reactivemongo.api.CursorOptions
// Create a options to specify a cursor is tailable
val opts = CursorOptions.empty.tailable
Companion:
object
Graph
Supertypes
class AnyVal
trait Matchable
class Any

Attributes

Companion:
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Allows to enrich a base cursor.

Allows to enrich a base cursor.

Attributes

Companion:
object
Graph
Supertypes
class Object
trait Matchable
class Any

Attributes

Companion:
trait
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
final class DB

The reference to a MongoDB database, obtained from a reactivemongo.api.MongoConnection.

The reference to a MongoDB database, obtained from a reactivemongo.api.MongoConnection.

import scala.concurrent.ExecutionContext
import reactivemongo.api.MongoConnection

def foo(connection: MongoConnection)(implicit ec: ExecutionContext) = {
 val db = connection.database("plugin")
 val _ = db.map(_("acoll")) // Collection reference
}

Attributes

connection

the reactivemongo.api.MongoConnection that will be used to query this database

failoverStrategy

the default failover strategy for sending requests

name

this database name

Graph
Supertypes
class Object
trait Matchable
class Any
final class FailoverStrategy

A failover strategy for sending requests. The default uses 10 retries: 125ms, 250ms, 375ms, 500ms, 625ms, 750ms, 875ms, 1s, 1125ms, 1250ms

A failover strategy for sending requests. The default uses 10 retries: 125ms, 250ms, 375ms, 500ms, 625ms, 750ms, 875ms, 1s, 1125ms, 1250ms

import scala.concurrent.duration._

reactivemongo.api.FailoverStrategy(
 initialDelay = 150.milliseconds,
 retries = 20,
 delayFactor = { `try` => `try` * 1.5D })

Attributes

Companion:
object
Graph
Supertypes
class Object
trait Matchable
class Any

FailoverStrategy utilities

FailoverStrategy utilities

Attributes

Companion:
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
class FlattenedCursor[T](val cursor: Future[Cursor[T]]) extends Cursor[T]

Attributes

Graph
Supertypes
trait Cursor[T]
class Object
trait Matchable
class Any
final class MongoConnection

A pool of MongoDB connections, obtained from a reactivemongo.api.AsyncDriver.

A pool of MongoDB connections, obtained from a reactivemongo.api.AsyncDriver.

Connection here does not mean that there is one open channel to the server: behind the scene, many connections (channels) are open on all the available servers in the replica set.

Example:

import scala.concurrent.ExecutionContext
import reactivemongo.api._

def foo(driver: AsyncDriver)(implicit ec: ExecutionContext) = {
 val con = driver.connect(List("localhost"))
 val db = con.flatMap(_.database("plugin"))
 val _ = db.map(_("acoll")) // Collection reference
}

Attributes

mongosystem

the reference to the internal reactivemongo.core.actors.MongoDBSystem Actor.

name

the unique name for the connection pool

supervisor

the name of the supervisor

Companion:
object
Graph
Supertypes
class Object
trait Matchable
class Any

Attributes

Companion:
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Attributes

Companion:
object
Graph
Supertypes
class Object
trait Matchable
class Any

MongoConnectionOptions factory.

reactivemongo.api.MongoConnectionOptions(nbChannelsPerNode = 10)

Attributes

Companion:
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
sealed trait ReadConcern

The Read Concern allows to control the consistency and isolation used to read data from replica sets.

The Read Concern allows to control the consistency and isolation used to read data from replica sets.

import reactivemongo.api.ReadConcern
import reactivemongo.api.bson.BSONDocument
import reactivemongo.api.bson.collection.BSONCollection

def queryBuilderWithReadConcern(coll: BSONCollection) =
 coll.find(BSONDocument.empty).
 readConcern(ReadConcern.Available)

Attributes

Companion:
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Available.type
object Linearizable.type
object Local.type
object Majority.type
object Snapshot.type

Attributes

Companion:
trait
Graph
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
sealed trait ReadPreference

MongoDB read preference enables to read from primary or secondaries with a predefined strategy.

MongoDB read preference enables to read from primary or secondaries with a predefined strategy.

import reactivemongo.api.ReadPreference

val pref: ReadPreference = ReadPreference.primary

Attributes

Companion:
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

ReadPreference utilities and factories.

ReadPreference utilities and factories.

Attributes

Companion:
trait
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

SCRAM-SHA-1 authentication (since MongoDB 3.6)

SCRAM-SHA-1 authentication (since MongoDB 3.6)

Attributes

Graph
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Self type

SCRAM-SHA-256 authentication (see MongoDB 4.0)

SCRAM-SHA-256 authentication (see MongoDB 4.0)

Attributes

Graph
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Self type
object Version

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Version.type
trait WrappedCursor[T] extends Cursor[T]

Cursor wrapper, to help to define custom cursor classes.

Cursor wrapper, to help to define custom cursor classes.

Attributes

See also:

CursorProducer

Graph
Supertypes
trait Cursor[T]
class Object
trait Matchable
class Any
trait WrappedCursorOps[T] extends CursorOps[T]

Internal cursor operations.

Internal cursor operations.

Attributes

Graph
Supertypes
trait CursorOps[T]
class Object
trait Matchable
class Any
Self type
final class WriteConcern

The write concern.

import scala.concurrent.ExecutionContext
import reactivemongo.api.{ DB, WriteConcern }
import reactivemongo.api.bson.BSONDocument

def foo(db: DB)(implicit ec: ExecutionContext) =
 db.collection("myColl").
   insert(ordered = false, WriteConcern.Acknowledged).
   one(BSONDocument("foo" -> "bar"))

Attributes

Companion:
object
Graph
Supertypes
class Object
trait Matchable
class Any

WriteConcern utilities.

WriteConcern utilities.

Attributes

Companion:
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

X509 authentication

X509 authentication

Attributes

Graph
Supertypes
trait Singleton
trait Product
trait Mirror
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Self type