throw new MongooseError(‘Mongoose.prototype.connect() no longer accepts a callback‘);

简介: throw new MongooseError(‘Mongoose.prototype.connect() no longer accepts a callback‘);
const mongoose = require("mongoose")
mongoose.connect("mongodb://127.0.0.1/student", (err) => {
    if (err) {
        return console.log(err);
    } else {
        console.log("数据库连接成功");
    }
})
// 抛出
module.exports = mongoose


以上是之前一直写的但是报错


throw new MongooseError('Mongoose.prototype.connect() no longer accepts a callback');


今天像以前一样写代码的时候发现跟平时写的一样 但是一直报这个错误 后来才发现是mongoose的版本更新了 后来请假别的大佬得知 需要把格式修改一下 修改成这个


const mongoose = require("mongoose")
// 消除严格模式
mongoose.set("strictQuery", true)
mongoose.connect("mongodb://127.0.0.1/interview")
const conn = mongoose.connection
conn.on("open", () => {
    console.log("ok");
})
conn.on("error", (err) => {
    console.log(err);
})
// 抛出
module.exports = mongoose


这样就可以正常执行了

目录
相关文章
|
6月前
|
JavaScript 前端开发
【报错】unhandled error during execution of watcher callback
JavaScript错误`unhandled error during execution of watcher callback`在Echarts图表渲染时出现,通常是因数据未获取到就尝试渲染导致。解决方法是在渲染前添加非空判断,如`if(value){开始渲染数据}`或`if(value !== undefined){开始渲染数据}`,确保数据加载完成后再执行渲染。
861 0
|
6月前
|
JavaScript 小程序 前端开发
[Vue warn]: Error in callback for watcher “fileList“: “TypeError: Cannot create property ‘uid‘ on st
[Vue warn]: Error in callback for watcher “fileList“: “TypeError: Cannot create property ‘uid‘ on st
159 0
|
5月前
|
前端开发 小程序 JavaScript
微信小程序-Unhandled promise rejection TypeError: Cannot read property ‘get‘ of undefined
微信小程序-Unhandled promise rejection TypeError: Cannot read property ‘get‘ of undefined
|
3月前
|
JavaScript
成功解决:Failed to resolve directive: mode
这篇文章介绍了如何解决Vue中遇到的"Failed to resolve directive: mode"错误的两个常见原因及其解决办法:确保指令的单词拼写正确,以及在创建Vue实例之前注册全局指令。
成功解决:Failed to resolve directive: mode
成功解决:Error in created hook: “ReferenceError: params is not defined“
该博客文章描述了作者解决"ReferenceError: params is not defined"错误的过程,原因是路由传递的params参数与调用方法中的参数名称冲突,最终通过检查接口参数解决了问题。
成功解决:Error in created hook: “ReferenceError: params is not defined“
|
6月前
|
JavaScript 开发者
vue解决报错Unable to preventDefault inside passive event listener invocation.
vue解决报错Unable to preventDefault inside passive event listener invocation.
628 0
|
11月前
SyntaxError: await is only valid in async function
SyntaxError: await is only valid in async function
|
关系型数据库 MySQL C++
Error:error C2601: ‘b‘ : local function definitions are illegal error C2063: ‘b‘ : not a function
Error:error C2601: ‘b‘ : local function definitions are illegal error C2063: ‘b‘ : not a function
177 0
|
JavaScript
[Vue warn]: Error in mounted hook: “TypeError: handler.call is not a function“
[Vue warn]: Error in mounted hook: “TypeError: handler.call is not a function“
284 0
[Vue warn]: Error in mounted hook: “TypeError: handler.call is not a function“