Getting Started

Modulus offers an integrated MongoDB solution. This guide will walk you through all the steps needed to create and begin using a Mongo database.

MongoDB Version: 2.4.9

Create Database

At the moment, databases can only be created through the web interface. Navigate to your User dashboard and select the Databases tab on the left.

To create a new database, click the "Create Database" button.

Create Database Dialog

On this dialog, enter the desired label of the database. This name is simply a convenience label and is not the actual name of the database within Mongo. Actual database names are created automatically by Modulus. You can optionally create a read/write user at this stage. If you do not create a user now, you must create one later in order to access your database.

Once complete, the popup will change with information about your newly created database.

Database Ready Dialog

The Mongo URI can be used to connect to your database from your application. The Mongo Console is the command used to connect to your instance using Mongo's command line tool. This information can also be retrieved at any time on the database dashboard.

Connecting to Your Database

Once the database has been created, it can be connected to like any other MongoDB instance. The connection information is displayed on the web interface. Database names are generated automatically by Modulus, in the above example the name is "enyrO4ma".

Mongoose

var mongoose = require('mongoose');

var db = mongoose.createConnection(
  'mongodb://user:pass@mongo.onmodulus.net:27017/enyrO4ma'
);

Native MongoDB Driver

var MongoClient = require('mongodb').MongoClient;

MongoClient.connect(
  'mongodb://user:pass@mongo.onmodulus.net:27017/enyrO4ma',
  function(err, db) {
    // Query the DB.
  }
);

Deleting

Databases can be deleted on the Administration tab on the database dashboard. All data will be destroyed and this action cannot be undone.

comments powered byDisqus