Permalink
Browse files

Added support for Mongo auth and passing in client

can now pass `user` and `password` in options to authenticate to
mongo database.

can now pass `client` in options, where `client` is a mongodb.Db
instance, and mongo driver will use that client rather than generating
one from the options.
  • Loading branch information...
1 parent 7b835a1 commit 8489cbcbb651f16ed7e797b407768350aa02a903 @dgreisen dgreisen committed Oct 19, 2012
Showing with 7 additions and 2 deletions.
  1. +7 −2 src/server/db/mongo.coffee
@@ -19,15 +19,20 @@ defaultOptions =
hostname: '127.0.0.1'
port: 27017
mongoOptions: {auto_reconnect: true}
-
+ client: null # an instance of mongodb.Db
+ user: null # an optional username for authentication
+ password: null # an optional password for authentication
# Valid options as above.
module.exports = MongoDb = (options) ->
options ?= {}
options[k] ?= v for k, v of defaultOptions
- client = new mongodb.Db(options.db, new mongodb.Server(options.hostname, options.port, options.mongoOptions))
+ client = options.client or new mongodb.Db(options.db, new mongodb.Server(options.hostname, options.port, options.mongoOptions))
+
+ if options.user and options.password
+ client.auth(options.user, options.password)
opsCollectionForDoc = (docName) -> 'ops.' + encodeURIComponent(docName).replace(/\./g, '%2E').replace(/-/g, '%2D')

0 comments on commit 8489cbc

Please sign in to comment.