MongoConnection

reactivemongo.api.MongoConnection
See theMongoConnection companion object
final class MongoConnection

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

Members list

Concise view

Value members

Concrete methods

Returns true if the connection has not been killed.

Returns true if the connection has not been killed.

Attributes

def authenticate(db: String, user: String, password: String, failoverStrategy: FailoverStrategy)(implicit ec: ExecutionContext): Future[SuccessfulAuthentication]

Authenticates the connection on the given database.

Authenticates the connection on the given database.

Attributes

db

the database name

failoverStrategy

the failover strategy for sending requests

import scala.concurrent.{ ExecutionContext, Future }
import reactivemongo.api.MongoConnection
def authDB(con: MongoConnection, user: String, pass: String)(
 implicit ec: ExecutionContext): Future[Unit] =
 con.authenticate("myDB", user, pass).map(_ => {})
 // with configured failover
password

the user password

user

the user name

See also:
def close()(implicit timeout: FiniteDuration): Future[_]

Closes this connection (closes all the channels and ends the actors).

Closes this connection (closes all the channels and ends the actors).

import scala.concurrent.{ ExecutionContext, Future }
import scala.concurrent.duration._

import reactivemongo.api.MongoConnection

def afterClose(con: MongoConnection)(
 implicit ec: ExecutionContext): Future[Unit] =
 con.close()(5.seconds).map { res =>
   println("Close result: " + res)
 }

Attributes

def database(name: String, failoverStrategy: FailoverStrategy)(implicit ec: ExecutionContext): Future[DB]

Returns a DB reference using this connection. The failover strategy is also used to wait for the node set to be ready, before returning an valid database reference.

Returns a DB reference using this connection. The failover strategy is also used to wait for the node set to be ready, before returning an valid database reference.

Attributes

failoverStrategy

the failover strategy for sending requests

import scala.concurrent.{ ExecutionContext, Future }
import reactivemongo.api.{ DB, MongoConnection }
def resolveDB(con: MongoConnection, name: String)(
 implicit ec: ExecutionContext): Future[DB] =
 con.database(name) // with configured failover
name

the database name

override def toString: String

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns:

a string representation of the object.

Definition Classes
Any