使用 createConnection 来替代 connect
MovieSchema.js
module.exports={
pic:String,
title:String,
slogo:String,
evaluate:String,
labels:Array,
rating:String
}
db.js
const mongoose = require("mongoose")
var mongodb = mongoose.createConnection( 'mongodb://127.0.0.1:27017/movies', {
useNewUrlParser: true,
useUnifiedTopology:true
});
var Schema = mongoose.Schema
module.exports ={
mongodb,
Schema
}
Top250.js
const {mongodb,Schema} = require("./baseDB/db-movies")
const MovieSchema = require("./Schema/MovieSchema")
const Top250Schema = new Schema(MovieSchema)
const Top250Model = mongodb.model("Top250",Top250Schema,"top250")
module.exports = Top250Model