class MongoConnection extends AnyRef

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

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 collection = db.map(_("acoll"))
}
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. MongoConnection
  2. AnyRef
  3. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new MongoConnection(supervisor: String, name: String, actorSystem: ActorSystem, mongosystem: ActorRef, options: MongoConnectionOptions)

    supervisor

    the name of the supervisor

    name

    the unique name for the connection pool

    mongosystem

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

Value Members

  1. def active: Boolean

    Returns true if the connection has not been killed.

    Returns true if the connection has not been killed.

    Annotations
    @inline()
  2. def authenticate(db: String, user: String, password: String, failoverStrategy: FailoverStrategy = options.failoverStrategy)(implicit ec: ExecutionContext): Future[SuccessfulAuthentication]

    Authenticates the connection on the given database.

    Authenticates the connection on the given database.

    db

    the database name

    user

    the user name

    password

    the user password

    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
    See also

    MongoConnectionOptions.credentials

    DB.authenticate

  3. 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)
      }
  4. def database(name: String, failoverStrategy: FailoverStrategy = options.failoverStrategy)(implicit ec: ExecutionContext): Future[DefaultDB]

    Returns a DefaultDB reference using this connection.

    Returns a DefaultDB 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.

    name

    the database name

    failoverStrategy

    the failover strategy for sending requests

    import scala.concurrent.{ ExecutionContext, Future }
    import reactivemongo.api.{ DefaultDB, MongoConnection }
    
    def resolveDB(con: MongoConnection, name: String)(
      implicit ec: ExecutionContext): Future[DefaultDB] =
      con.database(name) // with configured failover
  5. val options: MongoConnectionOptions
  6. def toString(): String
    Definition Classes
    MongoConnection → AnyRef → Any

Deprecated Value Members

  1. val actorSystem: ActorSystem
    Annotations
    @deprecated
    Deprecated

    (Since version 0.14.0) Internal: will be made private

  2. def askClose()(implicit timeout: FiniteDuration): Future[_]
    Annotations
    @deprecated
    Deprecated

    (Since version 0.19.4) Use close

  3. def authenticate(db: String, user: String, password: String): Future[SuccessfulAuthentication]
    Annotations
    @deprecated
    Deprecated

    (Since version 0.14.0) Use authenticate with failoverStrategy

  4. val mongosystem: ActorRef
    Annotations
    @deprecated
    Deprecated

    (Since version 0.17.0) Internal: will be made private

  5. val name: String
    Annotations
    @deprecated
    Deprecated

    (Since version 0.17.0) Internal: will be made private

  6. val supervisor: String
    Annotations
    @deprecated
    Deprecated

    (Since version 0.17.0) Internal: will be made private