mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-01-18 05:12:21 +01:00
Upgrades Mongoose to 4.11.1 Updates Mongoose connection implementation to accommodate deprecated features & connection options. Also, updates the Gulp Mocha tasks to reflect changes to the Mongoose implementation. Fixes tests to get the database from the existing Mongoose singleton. Derives from changes in https://github.com/meanjs/mean/pull/1816 Closes https://github.com/meanjs/mean/issues/1814
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Module dependencies.
|
|
*/
|
|
var _ = require('lodash'),
|
|
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 (callback) {
|
|
mongoose.Promise = config.db.promise;
|
|
|
|
var options = _.merge(config.db.options || {}, { useMongoClient: true });
|
|
|
|
mongoose
|
|
.connect(config.db.uri, options)
|
|
.then(function (connection) {
|
|
// Enabling mongoose debug mode if required
|
|
mongoose.set('debug', config.db.debug);
|
|
|
|
// Call callback FN
|
|
if (callback) callback(connection.db);
|
|
})
|
|
.catch(function (err) {
|
|
console.error(chalk.red('Could not connect to MongoDB!'));
|
|
console.log(err);
|
|
});
|
|
|
|
};
|
|
|
|
module.exports.disconnect = function (cb) {
|
|
mongoose.connection.db
|
|
.close(function (err) {
|
|
console.info(chalk.yellow('Disconnected from MongoDB.'));
|
|
return cb(err);
|
|
});
|
|
};
|