美文网首页
docker mongo设置

docker mongo设置

作者: Hi小胡 | 来源:发表于2020-11-19 12:04 被阅读0次
function connect() {
    let mongoose = require('mongoose');
    let DB_HOST = process.env.MONGO_HOST || "localhost";
    let DB_PORT = process.env.MONGO_PORT || 27017;
    let DB_URL = "mongodb://" + DB_HOST + ":" + DB_PORT + "/codemaker";
    //connect mongodb
    mongoose.Promise = global.Promise;
    mongoose.connect(DB_URL);

    //mongodb status
    mongoose.connection.on('connected', function () {
        console.log("mongodb connected success");
    });
    mongoose.connection.on('error', function (err) {
        console.log("mongodb connected error " + err);
    });
    mongoose.connection.on('disconnected', function () {
        console.log("mongodb disconnected");
    });
}

module.exports = {
    connect,
};

相关文章

网友评论

      本文标题:docker mongo设置

      本文链接:https://www.haomeiwen.com/subject/uqwkiktx.html