我在使用代码。
我试图连接到一个MongoDB数据库来存储值,但随后我得到了一个错误: UnHandledPromiseRejection
error => UnhandledPromiseRejectionWarning: Error: connect 13.234.193.81:27017
这是我用来连接到MongoDB的代码:
mongoose.connect('mongodb://node-shop:'+ process.env.MONGO_ATLAS_PW +'@node-rest-shop-shard-00-00-ylfa8.mongodb.net:27017,node-rest-shop-shard-00-01-ylfa8.mongodb.net:27017,node-rest-shop-shard-00-02-ylfa8.mongodb.net:27017/test?ssl=true&replicaSet=node-rest-shop-shard-0&authSource=admin&retryWrites=true', {
useNewUrlParser: true
});发布于 2019-04-22 11:56:37
你用的方式回报了你的承诺。你得用回调来处理。如果您还没有使用第二种方式,如下所示。异步/等待主体将工作
1.
mongoose.connect(uri, options, function(error) {
// Check error in initial connection. There is no 2nd param to the callback.
});
2.
// Or using promises
mongoose.connect(uri, options).then(
() => { /** ready to use. The `mongoose.connect()` promise resolves to undefined. */ },
err => { /** handle initial connection error */ }
);https://stackoverflow.com/questions/55792848
复制相似问题