【问题标题】:Unresolved function or method connect() mongoose未解析的函数或方法 connect() mongoose
【发布时间】:2022-12-03 15:13:22
【问题描述】:

I am learning Mongoose from JavaScript Everywhere book, and this is the code I had to write:

const mongoose = require(\'mongoose\');
const mongoose = require(\'mongoose\');
module.exports = {
  connect: DB_HOST => {
    mongoose.connect(DB_HOST);
    mongoose.connection.on(\'error\', err => {
      console.error(err);
      console.log(\'MongoDB connection error. Please make sure MongoDB is running.\');
      process.exit();
    });
  },
  close: () => {
    mongoose.connection.close();
  }
}

when i hover over connect and connection, it shows Unresolved function or method connect() and Unresolved variable connection accordingly. My guess is that the book about an older version of mongoose, and in the newest version it is simply removed. What is the new function and variable for it?

  • It\'s not removed, see the example on the Mongoose homepage. Have you actually tried running the code?
  • @robertklep yes, I ran it, but is there a way to solve this warning?
  • Fix your editor.
  • @robertklep, thnks

标签: javascript node.js database mongoose


【解决方案1】:
【解决方案2】:
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-01-24
  • 1970-01-01
  • 2014-03-01
  • 2019-01-10
  • 1970-01-01
  • 1970-01-01
  • 2018-05-02
相关资源
最近更新 更多