gpt4 book ai didi

node.js - 启动 mongodb 时出现 TransientTransactionError

转载 作者:可可西里 更新时间:2023-11-01 10:45:14 24 4
gpt4 key购买 nike

我无法解决 mongodb 连接问题。我在启动 Node 应用程序时收到以下错误。

这是我的 Mongoose 连接代码。

var mongoose = require('mongoose');

mongoose.Promise = global.Promise;
mongoose.connect(process.env.MONGODB_URI || 'mongodb://127.0.0.1:27017/ml').then(
() => { console.log('Connected to mongodb!') },
err => { console.log('Failed to connect to mongodb'); console.log(err); }
);

module.exports = {mongoose};

这里是错误。

Started up at port 80
Failed to connect to mongodb
{ MongoNetworkError: failed to connect to server [10.160.0.2:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 10.160.0.2:27017]
at Pool.<anonymous> (/home/shivamsharma_btp2/mlsever/magguland/node_modules/mongodb-core/lib/topologies/server.js:564:11)
at Pool.emit (events.js:189:13)
at Connection.<anonymous> (/home/shivamsharma_btp2/mlsever/magguland/node_modules/mongodb-core/lib/connection/pool.js:317:12)
at Object.onceWrapper (events.js:277:13)
at Connection.emit (events.js:189:13)
at Socket.<anonymous> (/home/shivamsharma_btp2/mlsever/magguland/node_modules/mongodb-core/lib/connection/connection.js:246:50)
at Object.onceWrapper (events.js:277:13)
at Socket.emit (events.js:189: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)]: {} }

这是我的谷歌云应用的防火墙规则。

最佳答案

找到解决方案了!

在启动服务器的命令前使用 sudo。

关于node.js - 启动 mongodb 时出现 TransientTransactionError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54616021/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com