这是我在终端上显示的错误。
{
message: 'connect ECONNREFUSED 127.0.0.1:27017',name: 'MongooseServerSelectionError',reason: TopologyDescription {
type: 'Single',setName: null,maxSetVersion: null,maxElectionId: null,servers: Map { 'localhost:27017' => [ServerDescription] },stale: false,compatible: true,compatibilityError: null,logicalSessionTimeoutMinutes: null,heartbeatFrequencyMS: 10000,localThresholdMS: 15,commonWireversion: null
},[Symbol(mongoErrorContextSymbol)]: {}
}
我在以下位置连接到数据库的代码:-
const mongoose = require("mongoose");
mongoose
.connect("mongodb://localhost:27017/playground",{
useNewUrlParser: true,useUnifiedTopology: true
})
.then(() => {
console.log("database connected");
})
.catch(err => {
console.log("Could not connect",err);
});
一切正常,直到我关闭笔记本电脑。我不知道为什么Mongodb指南针向我显示此错误“服务器选择在30000毫秒后超时”,我在本地主机上工作,仅