Database
Database
is a class that proxies the Db
model from MongoDB's Node driver.
It has some utility methods discussed below, but you should be able to call any driver methods directly.
#
Class Propertiesdb
#
The MongoClient
db instance recovered after a successful connection and calling MongoClient.db()
.
mongo
#
An instance of Mongo
.
Database#constructor
#
#
Signaturewarning
You won't usually need to instanciate the DB object yourself. This is done for you using the
Mongo.db()
method:
clear
#
#
SignatureClears the database by using the dropDatabase
method.
You can pass any options to be passed to that method.
atomic
#
#
SignatureThis method instanciates a driver's Session
and proxies Session.withTransaction
.
The first argument fn
is a function containing every query you want to perform in the transaction. It's only argument is session
, to be used in the queries options.
note
Your function must return a promise. You can use async
/ await
if you prefer and understand that they only wrap promises. This documentation will only use direct promises.
options
is an object passed to Session.withTransaction
.
transaction
#
#
SignatureThis method returns a new Transaction
instance. Please refer to its documentation.