Adds authenticate to db.open if a username and password are set.

This commit is contained in:
Timothy Marks 2012-08-14 22:31:49 +10:00
parent a54961923d
commit eaa2f026b0
1 changed files with 15 additions and 3 deletions

View File

@ -34,9 +34,21 @@ function MongoDB(s, schema, callback) {
var server = new mongodb.Server(s.host, s.port, {});
new mongodb.Db(s.database, server, {}).open(function (err, client) {
if (err) throw err;
this.client = client;
schema.client = client;
callback();
if (s.username && s.password) {
t = this;
client.authenticate(s.username, s.password, function(err, result) {
if (err) throw err;
t.client = client;
schema.client = client;
callback();
});
} else {
this.client = client;
schema.client = client;
callback();
}
}.bind(this));
}