Adds authenticate to db.open if a username and password are set.
This commit is contained in:
parent
a54961923d
commit
eaa2f026b0
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue