Tips:使用createConnection
//db.js
const mongoose = require("mongoose");
/* 1.连接本地数据库 */
var mongodb = mongoose.createConnection('mongodb://127.0.0.1:27017/wechat', {
useNewUrlParser: true,
useUnifiedTopology: true
});
var Schema = mongoose.Schema;
module.exports = {
mongodb,
Schema
};
//article.js
const {mongodb,Schema} = require("./baseDB/db");
const MovieSchema = require("./Schema/MovieSchema")
const Top250Schema = new Schema(MovieSchema);
const Top250Model = mongodb.model("Top250",Top250Schema,"top250");
module.exports = Top250Model;