Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit 8489cbcbb651f16ed7e797b407768350aa02a903 1 parent 7b835a1
@dgreisen dgreisen authored
Showing with 7 additions and 2 deletions.
  1. +7 −2 src/server/db/mongo.coffee
View
9 src/server/db/mongo.coffee
@@ -19,7 +19,9 @@ 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) ->
@@ -27,7 +29,10 @@ 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')
Please sign in to comment.
Something went wrong with that request. Please try again.