Returns true if the connection has not been killed.
Returns true if the connection has not been killed.
Authenticates the connection on the given database.
Authenticates the connection on the given database.
the database name
the user name
the user password
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
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) }
Returns a DB reference using this connection.
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.
the database name
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
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: