1. 使用 createConnection 来替代 connect

MovieSchema.js

  1. module.exports={
  2. pic:String,
  3. title:String,
  4. slogo:String,
  5. evaluate:String,
  6. labels:Array,
  7. rating:String
  8. }

db.js

  1. const mongoose = require("mongoose")
  2. var mongodb = mongoose.createConnection( 'mongodb://127.0.0.1:27017/movies', {
  3. useNewUrlParser: true,
  4. useUnifiedTopology:true
  5. });
  6. var Schema = mongoose.Schema
  7. module.exports ={
  8. mongodb,
  9. Schema
  10. }

Top250.js

  1. const {mongodb,Schema} = require("./baseDB/db-movies")
  2. const MovieSchema = require("./Schema/MovieSchema")
  3. const Top250Schema = new Schema(MovieSchema)
  4. const Top250Model = mongodb.model("Top250",Top250Schema,"top250")
  5. module.exports = Top250Model