Connect With mLab MongoDB Server Without Any Hiccup

Code Snippets 4 U

From : https://gist.github.com/arshdkhn1/b402fcada5117b8a2f17859a753bf9b9

// mongoose 4.3.x
var mongoose = require('mongoose');

/*
 * Mongoose by default sets the auto_reconnect option to true.
 * We recommend setting socket options at both the server and replica set level.
 * We recommend a 30 second connection timeout because it allows for
 * plenty of time in most operating environments.
 */
var options = {
    keepAlive: 300000,
    connectTimeoutMS: 30000,
    useNewUrlParser: true
};

var mongodbUri = 'mongodb://user:pass@host:port/db';

mongoose.connect(mongodbUri, options);
var conn = mongoose.connection;

conn.on('error', console.error.bind(console, 'connection error:'));

conn.once('open', function() {
    // Wait for the database connection to establish, then start the app.
});

Image of Page. If somehow that get lost (as of posting)

Leave a Reply

Your email address will not be published. Required fields are marked *

+ forty five = 52