Files
meanTorrent/config/lib/mongoose.js
Liran Tal f8384040a4 fix(mongoose): fixing mongoose deprecation notice for promises lib (#1691)
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`
2016-12-25 11:23:57 +02:00

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);
});
};