将我的数据库从Compose迁移到Mongodb Altas之后。我将MONGO_URI更改为mongodb Altas,db.once('open',
无法正常工作
const mongoose = require('mongoose'),
fs = require('fs'),
Promise = require('bluebird'),
modelsPath = './models',
glob = Promise.promisify(require('glob')),
_ = require('lodash');
const models = () => glob(`${modelsPath}/**/*.js`);
module.exports = {
init: () => {
mongoose.connect(process.env.MONGO_URI);
let db = mongoose.connection;
models()
.then(m => {
m.forEach(model => require(`../${model}`));
db.on('error', console.error.bind(console, 'Error connecting to mongodb: '));
db.once('open', console.log.bind(console, 'Database connected.'));
mongoose.Promise = require('bluebird');
});
}
};