Documentation


MongoDB

Change MongoDB password

Open your application's information tab in admin console and scroll to MongoDB section.
Click the Change password link and set a new password for your account. The change will be applied within 60 seconds.

How to connect to your MongoDB from Node.js / io.js

Add MongoDB native drivers to your package.json on your local machine by issuing the following command.

$ npm install mongodb --save

Upload your app's code to EvenNode through FTP or Git deployment.

EvenNode provides environment variable called APP_CONFIG which holds all information necessary to connect to your MongoDB instance from your Node.js application.

APP_CONFIG = {
  "mongo": {
    "hostString": "mongodb:27017/db_name",
    "user": "username",
    "db": "db_name"
  }
}

In your app.js connect to your MongoDB with the following code

var mongoPassword = 'your_password_here';
			
var http = require('http');
var server = http.createServer(function(req, res) {
  res.writeHead(200, { 'Content-Type': 'text/plain' });

  var config = JSON.parse(process.env.APP_CONFIG);
  var MongoClient = require('mongodb').MongoClient;

  MongoClient.connect(
    "mongodb://" + config.mongo.user + ":" + encodeURIComponent(mongoPassword) + "@" + 
    config.mongo.hostString, 
    function(err, db) {
      if(!err) {
        res.end("We are connected to MongoDB");
      } else {
        res.end("Error while connecting to MongoDB");
      }
    }
  );
});
server.listen(process.env.PORT);

If this is the first time you are connecting to MongoDB, don't forget to set your password in the admin console.

How to connect to MongoDB from your computer

Connecting to MongoDB from your computer is easy.
First make sure that you have installed MongoDB and set password for EvenNode's MongoDB.
Then open web console, go to your app's info section and locate MongoDB shell command.

Open command line (Windows) or terminal (OS X) and use the MongoDB shell command to connect to MongoDB. For example:

$ mongo "mongodb://host:27017" -u user -p

Mongo will prompt you for your password and you're good to go.