我正在尝试连接到mongodb地图集,但是我还是把它找回来了。
MongoNetworkError:首次连接[MongoNetworkError:连接超时]时,无法连接到服务器[accounting-shard-00-01-6tg4q.mongodb.net:27017]
mongoose
.connect(
"mongodb+srv://user:password@url.mongodb.net/accounting?retryWrites=true&w=majority",
{
useNewUrlParser: true
}
)
.then(() => {
console.log("Connected to Mongo database for testing");
app.listen(8000);
})
.catch(error => {
console.log(error);
});
其余错误如下
{ MongoNetworkError: failed to connect to server [accounting-shard-00-01-6tg4q.mongodb.net:27017] on first connect [MongoNetworkError: connection timed out]
at Pool.<anonymous> (/home/numbers/workspace/web/server/numbersServer/node_modules/mongodb-core/lib/topologies/server.js:431:11)
at Pool.emit (events.js:198:13)
at connect (/home/numbers/workspace/web/server/numbersServer/node_modules/mongodb-core/lib/connection/pool.js:557:14)
at makeConnection (/home/numbers/workspace/web/server/numbersServer/node_modules/mongodb-core/lib/connection/connect.js:39:11)
at callback (/home/numbers/workspace/web/server/numbersServer/node_modules/mongodb-core/lib/connection/connect.js:261:5)
at TLSSocket.err (/home/numbers/workspace/web/server/numbersServer/node_modules/mongodb-core/lib/connection/connect.js:286:7)
at Object.onceWrapper (events.js:286:20)
at TLSSocket.emit (events.js:198:13)
at TLSSocket.Socket._onTimeout (net.js:442:8)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)
name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ],
[Symbol(mongoErrorContextSymbol)]: {} }
答案 0 :(得分:0)
我也遇到了一个错误,原来那时候我的学校正在阻止向mongo发送网络请求,但是当我使用vpn时,可以尝试一下。