forked from isitchristmas/web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongo.js
More file actions
29 lines (27 loc) · 786 Bytes
/
mongo.js
File metadata and controls
29 lines (27 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var mongodb = require('mongodb');
module.exports = {
mongodb: mongodb,
connect: function(config, callback) {
var db = new mongodb.Db(
config.database,
new mongodb.Server(config.host, config.port,
{auto_reconnect: true}),
{safe: true}
);
// open the database, auth if needed
db.open(function(err, data) {
if (data) {
if (config.username && config.password) {
data.authenticate(config.username, config.password, function(err2, status) {
if (status)
callback(data);
else
console.log("Error authenticating: " + err2);
});
} else
callback(data);
} else
console.log("Error opening MongodB: " + err);
});
}
};