我的连接代码在下面输入。我正在尝试连接到 MongoDB atlas 免费共享集群,但一直收到错误消息,提示无法在第一时间连接到服务器。
const express = require("express");
const app = express();
const morgan = require("morgan");
const bodyParser = require("body-parser");
const mongoose = require("mongoose");
mongoose.Promise = require('bluebird');
const productRoutes = require("./api/routes/products");
const orderRoutes = require("./api/routes/orders");
mongoose.connect(
"mongodb://username:password6@cluster0-shard-00-00-3xdjv.mongodb.net:27017,cluster0-shard-00-01-3xdjv.mongodb.net:27017,cluster0-shard-00-02-3xdjv.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin",
{
useMongoClient: true
}
) .then(() => { // if all is ok we will be here
return server.start();
})
.catch(err => { // we will not be here...
console.error('App starting error:', err.stack);
process.exit(1);
});
有人可以解释为什么我不断收到此错误:
应用启动错误:
MongoError:第一次连接时无法连接到服务器 [cluster0-shard-00-00-3xdjv.mongodb.net:27017] [MongoError: getaddrinfo EAI_AGAIN cluster0-shard-00-00-3xdjv.mongodb.net:27017].. ...