【发布时间】:2021-01-12 09:24:07
【问题描述】:
我已经安装了 mongodb 4.2.3 版,但是我无法连接我的克隆项目。显示以下错误
MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connection timed out]
但我可以将数据库与我的本地项目连接起来,还可以通过执行事务进行检查。 mongo 命令输出如下所示
MongoDB shell version v4.4.3
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("a6f6b036-ad62-4e38-b0d2-50bfda540016") }
MongoDB server version: 4.4.3
---
The server generated these startup warnings when booting:
2021-01-12T12:43:25.733+05:30: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem
2021-01-12T12:43:31.420+05:30: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
---
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).
The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.
To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---
>
我的mongodb连接代码如下
// Connect to mongodb
var connect = function () {
var options = {
keepAlive: 1,
autoReconnect: true,
useNewUrlParser: true,
useUnifiedTopology:true,
serverSelectionTimeoutMS:60000,
socketTimeoutMS:60000
};
mongoose.connect(config.db, options);
};
connect();
mongoose.connection.on("error", console.log);
mongoose.connection.on("disconnected", connect);
我也尝试过增加超时但没有解决方案。
【问题讨论】: