Skip to content

Instantly share code, notes, and snippets.

@EchoAbstract
Forked from ivanstoyanov/dbManager.coffee
Created June 25, 2012 22:49
Show Gist options
  • Save EchoAbstract/2991961 to your computer and use it in GitHub Desktop.
Save EchoAbstract/2991961 to your computer and use it in GitHub Desktop.
Node/Mongo Replica set connect string
mongo = require 'mongodb'
# full connect string
mongodbURI = "mongodb://
#{process.env.MONGO_USER}:#{process.env.MONGO_PASSWORD}@
mongoA.company.com,mongoB.company.com,mongoC.company.com/
admin?replicaSet=company&autoReconnect=true&connectTimeoutMS=500"
# obtaining a connection is now simple
mongo.connect mongodbURI, (err, db) =>
if (err)
throw new Error("Unable to connect to the database")
else
console.log "Connected"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment