MongoDB Atlas-如何在共享虚拟主机上修复“ TransientTransactionError”

时间:2019-06-18 06:46:47

标签: node.js shared-hosting mongodb-atlas

TransientTransactionError尝试从共享的Web主机连接到Mongo Atlas

我实际上曾经在某一点上工作过,但是我不得不擦除并重新启动我的Web主机上的项目。现在看来,在尝试连接到Atlas时,我总是收到上述错误。我已经尝试将IP地址列入白名单,包括我的服务器IP以及Atlas中的0.0.0.0/0(允许所有通配符)。

我也尝试使用“完整驱动程序”代码段代替猫鼬,但仍然收到相同的错误。最后,我想指出的是,完全相同的代码在我的本地计算机上也可以正常工作。

这是我的职能:

    const mongoose = require("mongoose");
    const config = require("./config");
    module.exports = cb => {
        if (mongoose.connection.readyState < 1) {
            mongoose.connect(config.db).then(
                () => {
                    console.log("Database linking successful!");
                    return cb ? cb : null;
                },
                err => {
                console.log("Failed to connect to database.", err);
                }
            );
        }
    };

以下是错误消息的样子:

{ MongoNetworkError: failed to connect to server [<mongodb-shard-goes-here>.mongodb.net:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 54.145.177.180:27017]
    at Pool.<anonymous> (/home/titanesp/public_html/server/node_modules/mongodb-core/lib/topologies/server.js:431:11)
    at Pool.emit (events.js:182:13)
    at connect (/home/titanesp/public_html/server/node_modules/mongodb-core/lib/connection/pool.js:557:14)
    at makeConnection (/home/titanesp/public_html/server/node_modules/mongodb-core/lib/connection/connect.js:39:11)
    at callback (/home/titanesp/public_html/server/node_modules/mongodb-core/lib/connection/connect.js:261:5)
    at TLSSocket.err (/home/titanesp/public_html/server/node_modules/mongodb-core/lib/connection/connect.js:286:7)
    at Object.onceWrapper (events.js:273:13)
    at TLSSocket.emit (events.js:182:13)
    at emitErrorNT (internal/streams/destroy.js:82:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)
  name: 'MongoNetworkError',
  errorLabels: [ 'TransientTransactionError' ],
  [Symbol(mongoErrorContextSymbol)]: {} }

0 个答案:

没有答案