【发布时间】:2018-01-08 08:03:54
【问题描述】:
在 node.js 中构建基本练习聊天应用时,我遇到了上述问题。
我的 express.js 代码:
var mongoose = require('mongoose')
var dbUrl = 'mongodb://ChatbotAdmin:ChatbotAdmin@ds239177.mlab.com:39177/learning_node'
mongoose.connect(dbUrl, (err) => {
console.log('Connected')
})
这是完整的错误:
(node:10192) UnhandledPromiseRejectionWarning: Unhandled promise rejection
(rejection id: 1): MongoNetworkError: connection 0 to
ds239177.mlab.com:39177 closed
(node:10192) [DEP0018] DeprecationWarning: Unhandled promise rejections are
deprecated. In the future, promise rejections that are not handled will
terminate the Node.js process with a non-zero exit code.
我尝试添加 {useMongoClient: true},就像这个家伙 The options [useMongoClient] is not supported 一样。只是发现他在猫鼬 5 中所做的那样,没有必要(也没有帮助)。
我进一步研究了:
mongoose.Promise = global.Promise
我有同样的错误。
This 问题也没有帮助。
我只是回退到早期版本的 mongoose,但我很想知道解决方案是什么......
【问题讨论】:
-
为了清楚起见,其余代码中没有使用任何承诺。
-
当你从猫鼬那里得到任何结果时处理你的承诺
-
@ManjeetThakur 不清楚。另外,正如我刚刚提到的,我还没有使用任何承诺。
-
真正的错误是
MongoNetworkError: connection 0 to ds239177.mlab.com:39177 closed,来自mongodb-core。 -
@MikaS 究竟是什么意思?
标签: javascript node.js mongodb express mongoose