Skip to content

Instantly share code, notes, and snippets.

@johnnyhalife
Created June 25, 2013 15:16
Show Gist options
  • Save johnnyhalife/5859303 to your computer and use it in GitHub Desktop.
Save johnnyhalife/5859303 to your computer and use it in GitHub Desktop.
// estamos usando mongoskin (npm install mongoskin)
var mongoskin = require('mongoskin');
// Si te estas conectando a un cluster con replica set, etc.
var matches = /mongodb:\/\/([^:]+):([^@]+)@([^\/]+)\/(.*)/.exec(process.env.MONGOLAB_URI);
var servers = matches[3].split(',').map(function(e){ return e + "?auto_reconnect=true&poolSize=4"; });
var dbOpts = {username: matches[1], password: matches[2], database: matches[4], safe: true, native_parser: false };
var socketOptions = { keepAlive: 1, connectTimeoutMS: 0, socketTimeoutMS: 0};
var db = mongoskin.db(servers, dbOpts, { rs_name: "rs-ds041197", socketOptions: socketOptions });
// Si te estas conectando derecho a la base
var db = mongoskin.db(process.env.MONGOLAB_URI + "?auto_reconnect=true&poolSize=4", {safe: true});
module.exports = db;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment