Tips:使用createConnection

    1. //db.js
    2. const mongoose = require("mongoose");
    3. /* 1.连接本地数据库 */
    4. var mongodb = mongoose.createConnection('mongodb://127.0.0.1:27017/wechat', {
    5. useNewUrlParser: true,
    6. useUnifiedTopology: true
    7. });
    8. var Schema = mongoose.Schema;
    9. module.exports = {
    10. mongodb,
    11. Schema
    12. };
    1. //article.js
    2. const {mongodb,Schema} = require("./baseDB/db");
    3. const MovieSchema = require("./Schema/MovieSchema")
    4. const Top250Schema = new Schema(MovieSchema);
    5. const Top250Model = mongodb.model("Top250",Top250Schema,"top250");
    6. module.exports = Top250Model;