-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathdb.js
46 lines (34 loc) · 1005 Bytes
/
db.js
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var connectionString, db, mongoose, options;
mongoose = require('mongoose');
mongoose = require('mongoose');
var config = require('config');
var host = config.get('mongodb.host');
var port = config.get('mongodb.port');
var db = config.get('mongodb.db');
connectionString = 'mongodb://' + host + ':' + port + '/' + db + '';
options = {
db: {
native_parser: true
},
server: {
auto_reconnect: true,
poolSize: 5
}
//,
// user: 'guojia',
// pass: 'guojia.ng'
};
mongoose.connect(connectionString, options, function(err, res) {
if (err) {
console.log('[mongoose log] Error connecting to: ', +connectionString + '. ' + err);
return process.exit(1);
} else {
return console.log('[mongoose log] Successfully connected to: ', +connectionString);
}
});
db = mongoose.connection;
db.on('error', console.error.bind(console, 'mongoose connection error:'));
db.once('open', function() {
return console.log('mongoose open success');
});
module.exports = db;