connect2mongo
Advanced tools
Comparing version 0.0.2 to 0.0.3
11
db.js
@@ -10,7 +10,8 @@ var BPromise = require('bluebird'); | ||
* @param {String} db MongoDB Database | ||
* @param {Object} auth An object containing User Authentication information {user: 'user1', password: 'pass'} | ||
* @param {String} username The Username for authentication | ||
* @param {String} password The Password for authentication | ||
* @resolve {Object} database A MongoDB Connection Instance | ||
* @reject {Error} err The Error Object | ||
*/ | ||
exports.connect = function (host, port, db, auth) { | ||
exports.connect = function (host, port, db, username, password) { | ||
var fallback = function (value, fallback) { | ||
@@ -20,5 +21,5 @@ return value || fallback; | ||
var genUser = function (auth) { | ||
if (auth.user && auth.pas) { | ||
return fallback(auth.user) + ':' + fallback(auth.password) + '@'; | ||
var genUser = function (username, password) { | ||
if (username && password) { | ||
return fallback(username) + ':' + fallback(password) + '@'; | ||
} else { | ||
@@ -25,0 +26,0 @@ return false; |
{ | ||
"name": "connect2mongo", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "A library to help you connect to mongodb", | ||
@@ -5,0 +5,0 @@ "main": "db.js", |
20
query.js
@@ -6,2 +6,22 @@ var BPromise = require('bluebird'); | ||
* @param {String} database A MongoDB Connection Instance | ||
* @param {String} username The Username for authentication | ||
* @param {String} password The Password for authentication | ||
* @resolve {Object} result The authentication's result | ||
* @reject {Error} err The Error Object | ||
*/ | ||
exports.authenticate = function (database, username, password, options) { | ||
return new BPromise(function (resolve, reject) { | ||
db.authenticate(username, password, options, function (err, result) { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(result); | ||
} | ||
}); | ||
}); | ||
}; | ||
/** | ||
* Get all the Documents of a MongoDB Collection | ||
* @param {String} database A MongoDB Connection Instance | ||
* @param {String} collection The MongoDB Collection name | ||
@@ -8,0 +28,0 @@ * @resolve {Array} documents The Documents of that collection |
21044
567