-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongoose.js
More file actions
36 lines (30 loc) · 896 Bytes
/
Copy pathmongoose.js
File metadata and controls
36 lines (30 loc) · 896 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
30
31
32
33
34
35
36
'use strict';
var chalk = require('chalk'),
models = require('./config/models').server.models,
path = require('path'),
mongoose = require('mongoose');
module.exports.loadModels = function (callback) {
console.log('loading models');
models.forEach(function (modelPath) {
require(path.resolve(modelPath));
});
if (callback) callback();
};
module.exports.connect = function (cb) {
var _this = this;
var db = mongoose.connect('mongodb://localhost:27017/UberDB', { useMongoClient : true }, function(err) {
if (err) {
console.error(chalk.red('Could not connect to MongoDB!'));
console.log(err);
} else {
mongoose.Promise = global.Promise;
if (cb) cb(db);
}
});
};
module.exports.disconnect = function (cb) {
mongoose.disconnect(function (err) {
console.info(chalk.yellow('Disconnedtec from MongoDB'));
cb(err);
});
};