无法连接到我的 MongoDB 数据库,在 Mongodb Compass 上出现此错误 "Server Selection Timed Out After 3000ms"
Can't connect to my MongoDB DataBase, getting this error "Server Selection Timed Out After 3000ms" on Mongodb Compass
这是我在终端上显示的错误。
{
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 指南针向我显示此错误 "Server selection timed out after 30000 ms",我在本地主机上工作,只有
您说“...在您关闭计算机之前一切正常...”,很可能是 mongod process exited on shut down. Can you try restarting the mongod
process and connect again, details on how to start the process are here For Windows and For Mac。
为避免在重新启动或关闭系统时再次出现此类问题,请考虑将 mongod 进程作为服务启动,如何启动取决于您使用的 OS,但是,您可以在安装页面上找到完整的说明集。例如,如果您使用的是 Mac,则说明是 here。
我 运行 mongo 和 mongod 在终端中它没有工作。
windows 的解决方案,但应该类似于 mac
在windows 打开任务管理器 || Ctrl + shift + ESC > select 服务选项卡 > 搜索 mongo 数据库 > 右键单击 > 启动服务
扩展@Maduekew 的答案,在 Windows 上,单击服务以仅过滤掉服务,然后搜索 MongoDB,如果状态栏显示 Stopped
,请右键单击并然后 select Start
.
这是我在终端上显示的错误。
{
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 指南针向我显示此错误 "Server selection timed out after 30000 ms",我在本地主机上工作,只有
您说“...在您关闭计算机之前一切正常...”,很可能是 mongod process exited on shut down. Can you try restarting the mongod
process and connect again, details on how to start the process are here For Windows and For Mac。
为避免在重新启动或关闭系统时再次出现此类问题,请考虑将 mongod 进程作为服务启动,如何启动取决于您使用的 OS,但是,您可以在安装页面上找到完整的说明集。例如,如果您使用的是 Mac,则说明是 here。
我 运行 mongo 和 mongod 在终端中它没有工作。
windows 的解决方案,但应该类似于 mac
在windows 打开任务管理器 || Ctrl + shift + ESC > select 服务选项卡 > 搜索 mongo 数据库 > 右键单击 > 启动服务
扩展@Maduekew 的答案,在 Windows 上,单击服务以仅过滤掉服务,然后搜索 MongoDB,如果状态栏显示 Stopped
,请右键单击并然后 select Start
.