The createUser command.
The createUser command.
Aborts the transaction associated with the current client session (since MongoDB 4.0), if any otherwise does nothing .
Aborts the transaction associated with the current client session (since MongoDB 4.0), if any otherwise does nothing .
The database reference with transaction aborted (but not session)
Aborts the transaction associated with the current client session (since MongoDB 4.0), if any otherwise does nothing .
Aborts the transaction associated with the current client session (since MongoDB 4.0), if any otherwise does nothing .
import scala.concurrent.ExecutionContext import reactivemongo.api.DB def equivalentTo(db: DB)(implicit ec: ExecutionContext) = db.abortTransaction(failIfNotStarted = false)
The database reference with transaction aborted (but not session)
Returns a reactivemongo.api.Collection reference from this database (alias for the collection method).
Returns a reactivemongo.api.Collection reference from this database (alias for the collection method).
the Collection type
the name of the collection to resolve
the failover strategy to override the default one
Authenticates the connection on this database.
Authenticates the connection on this database.
the name of the user
the user password
MongoConnection.authenticate
Returns a reactivemongo.api.Collection reference from this database.
Returns a reactivemongo.api.Collection reference from this database.
the Collection type
the name of the collection to resolve
the failover strategy to override the default one
import reactivemongo.api.DB def resolveColl(db: DB) = db.collection("acoll")
Returns the names of the collections in this database.
Returns the names of the collections in this database.
import scala.concurrent.{ ExecutionContext, Future } import reactivemongo.api.DB def listCollections(db: DB)( implicit ec: ExecutionContext): Future[List[String]] = db.collectionNames
Commits the transaction associated with the current client session (since MongoDB 4.0), if any otherwise does nothing .
Commits the transaction associated with the current client session (since MongoDB 4.0), if any otherwise does nothing .
import scala.concurrent.ExecutionContext import reactivemongo.api.DB def commitIt(db: DB)(implicit ec: ExecutionContext) = db.commitTransaction(failIfNotStarted = true)
The database reference with transaction commited (but not session)
Commits the transaction associated with the current client session (since MongoDB 4.0), if any otherwise does nothing .
Commits the transaction associated with the current client session (since MongoDB 4.0), if any otherwise does nothing .
import scala.concurrent.ExecutionContext import reactivemongo.api.DB def equivalentTo(db: DB)(implicit ec: ExecutionContext) = db.commitTransaction(failIfNotStarted = false)
The database reference with transaction commited (but not session)
the reactivemongo.api.MongoConnection that will be used to query this database
Create the user with given properties.
Create the user with given properties.
import scala.concurrent.{ ExecutionContext, Future } import reactivemongo.api.{ DB, ScramSha256Authentication, ScramSha1Authentication, WriteConcern } import reactivemongo.api.commands.UserRole def createReadWriteUser(db: DB, name: String)( implicit ec: ExecutionContext): Future[Unit] = db.createUser( user = name, pwd = None, // no initial password roles = List(UserRole("readWrite")), digestPassword = true, writeConcern = WriteConcern.Default, restrictions = List.empty, mechanisms = List( ScramSha1Authentication, ScramSha256Authentication))
the type of custom data associated with the created user
the name of the user to be created
the user password (not required if the database uses external credentials)
the custom data to associate with the user account
the roles granted to the user, possibly an empty to create users without roles
when true, the mongod instance will create the hash of the user password (default: true
)
the optional level of write concern
the authentication restriction
the authentication mechanisms (e.g. ScramSha1Authentication)
Drops this database.
Drops this database.
import scala.concurrent.{ ExecutionContext, Future } import reactivemongo.api.DB def dropDB(db: DB)( implicit ec: ExecutionContext): Future[Unit] = db.drop()
Ends (closes) the session associated with this database reference (since MongoDB 3.6), if any otherwise does nothing .
Ends (closes) the session associated with this database reference (since MongoDB 3.6), if any otherwise does nothing .
The database reference with session ended
Ends (closes) the session associated with this database reference (since MongoDB 3.6), if any otherwise does nothing .
Ends (closes) the session associated with this database reference (since MongoDB 3.6), if any otherwise does nothing .
import scala.concurrent.ExecutionContext import reactivemongo.api.DB def equivalentTo(db: DB)(implicit ec: ExecutionContext) = db.endSession(failIfNotStarted = false)
The database reference with session ended
the default failover strategy for sending requests
EXPERIMENTAL: API may change without notice.
EXPERIMENTAL: API may change without notice.
The GridFS with the default serialization.
The GridFS with the default serialization.
the type of serialization
the serialization pack
the collection prefix
The GridFS with the default serialization.
The GridFS with the default serialization.
the collection prefix
The GridFS with the default serialization and collection prefix.
The GridFS with the default serialization and collection prefix.
import reactivemongo.api.DB import reactivemongo.api.bson.BSONDocument def findFile(db: DB, query: BSONDocument) = db.gridfs.find(query)
Returns an index manager for this database.
Returns an index manager for this database.
import scala.concurrent.{ ExecutionContext, Future } import reactivemongo.api.DB import reactivemongo.api.indexes.NSIndex def listIndexes(db: DB)( implicit ec: ExecutionContext): Future[List[String]] = db.indexesManager.list().map(_.flatMap { (ni: NSIndex) => ni.index.name.toList })
Kills (aborts) the session associated with this database reference (since MongoDB 3.6), if any otherwise does nothing .
Kills (aborts) the session associated with this database reference (since MongoDB 3.6), if any otherwise does nothing .
The database reference with session aborted
Kills (aborts) the session associated with this database reference (since MongoDB 3.6), if any otherwise does nothing .
Kills (aborts) the session associated with this database reference (since MongoDB 3.6), if any otherwise does nothing .
import scala.concurrent.ExecutionContext import reactivemongo.api.DB def equivalentTo(db: DB)(implicit ec: ExecutionContext) = db.killSession(failIfNotStarted = false)
The database reference with session aborted
this database name
The serialization pack (BSON by default).
Tests if the server, resolved according to the given read preference, responds to commands.
Tests if the server, resolved according to the given read preference, responds to commands.
true if successful (even if the server is write locked)
MongoDB 3.0
import scala.concurrent.{ ExecutionContext, Future } import reactivemongo.api.DB def pingDB(db: DB)( implicit ec: ExecutionContext): Future[Boolean] = db.ping() // with default ReadPreference
Renames a collection.
Can only be executed if the this database reference is the admin
one.
import scala.concurrent.{ ExecutionContext, Future } import reactivemongo.api.DB def addCollSuffix( admin: DB, coll: String, suffix: String)(implicit ec: ExecutionContext): Future[Unit] = admin.renameCollection("myDB", coll, coll + suffix).map(_ => {})
the name of the database where the collection exists with the current
name
the current name of the collection, in the specified db
the new name of this collection (inside the same db
)
If a collection of name to
already exists, then drops that collection before renaming this one.
a failure if the dropExisting option is false and the target collection already exists
Run a raw command (represented by a document).
Run a raw command (represented by a document).
import reactivemongo.api.FailoverStrategy import reactivemongo.api.bson.BSONDocument def getUsers(db: reactivemongo.api.DB) = db.runCommand(BSONDocument("usersInfo" -> 1), FailoverStrategy.default)
the command to be executed on the current database
the failover strategy to override the default one
A cursor for the command results
the reactivemongo.api.commands.Command type
the command to be executed on the current database
the failover strategy to override the default one
the writer for the command
A cursor for the command results
the result type
the reactivemongo.api.commands.Command type
the command to be executed on the current database
the failover strategy to override the default one
the read preference for the result
the writer for the command
the reader for the result of command execution
A single result from command execution
Starts a new session (since MongoDB 3.6).
Starts a new session (since MongoDB 3.6).
import scala.concurrent.ExecutionContext import reactivemongo.api.DB def startIt(db: DB)(implicit ec: ExecutionContext) = db.startSession(failIfAlreadyStarted = true)
if true fails if a session is already started
The database reference updated with a new session, if none is already started with the current reference.
Starts a new session (since MongoDB 3.6), does nothing if a session has already being started .
Starts a new session (since MongoDB 3.6), does nothing if a session has already being started .
import scala.concurrent.ExecutionContext import reactivemongo.api.DB def equivalentTo(db: DB)(implicit ec: ExecutionContext) = db.startSession(failIfAlreadyStarted = false)
The database reference updated with a new session
Starts a transaction (since MongoDB 4.0), if none is already started with the current client session otherwise does nothing.
Starts a transaction (since MongoDB 4.0), if none is already started with the current client session otherwise does nothing.
It fails if no session is previously started (see startSession
).
import scala.concurrent.ExecutionContext import reactivemongo.api.{ DB, WriteConcern } def doIt(db: DB, aWriteConcern: Option[WriteConcern])( implicit ec: ExecutionContext) = db.startTransaction(aWriteConcern, failIfAlreadyStarted = true)
the write concern for the transaction operation
The database reference with transaction.
Starts a transaction (since MongoDB 4.0), if none is already started with the current client session otherwise does nothing.
Starts a transaction (since MongoDB 4.0), if none is already started with the current client session otherwise does nothing.
It fails if no session is previously started (see startSession
).
import scala.concurrent.ExecutionContext import reactivemongo.api.{ DB, WriteConcern } def equivalentTo(db: DB, aWriteConcern: Option[WriteConcern])( implicit ec: ExecutionContext) = db.startTransaction(aWriteConcern, failIfAlreadyStarted = false)
the write concern for the transaction operation
The database reference with transaction.
The reference to a MongoDB database, obtained from a reactivemongo.api.MongoConnection.