mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-01-16 12:22:26 +01:00
If no promises library set correctly for the mongoose.Promise property then the following warning notice is omitted by mongoose: `DeprecationWarning: Mongoose: mpromise (mongoose's default promise library) is deprecated, plug in your own promise library instead: http://mongoosejs.com/docs/promises.html`
49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Module dependencies.
|
|
*/
|
|
var config = require('../config'),
|
|
chalk = require('chalk'),
|
|
path = require('path'),
|
|
mongoose = require('mongoose');
|
|
|
|
// Load the mongoose models
|
|
module.exports.loadModels = function (callback) {
|
|
// Globbing model files
|
|
config.files.server.models.forEach(function (modelPath) {
|
|
require(path.resolve(modelPath));
|
|
});
|
|
|
|
if (callback) callback();
|
|
};
|
|
|
|
// Initialize Mongoose
|
|
module.exports.connect = function (cb) {
|
|
var _this = this;
|
|
|
|
mongoose.Promise = config.db.promise;
|
|
|
|
var db = mongoose.connect(config.db.uri, config.db.options, function (err) {
|
|
// Log Error
|
|
if (err) {
|
|
console.error(chalk.red('Could not connect to MongoDB!'));
|
|
console.log(err);
|
|
} else {
|
|
|
|
// Enabling mongoose debug mode if required
|
|
mongoose.set('debug', config.db.debug);
|
|
|
|
// Call callback FN
|
|
if (cb) cb(db);
|
|
}
|
|
});
|
|
};
|
|
|
|
module.exports.disconnect = function (cb) {
|
|
mongoose.disconnect(function (err) {
|
|
console.info(chalk.yellow('Disconnected from MongoDB.'));
|
|
cb(err);
|
|
});
|
|
};
|