阅读文档后,这对我来说是解决问题的方法:http :
//mongoosejs.com/docs/promises.html
该文档中的示例使用的是bluebird Promise库,但我选择使用本机ES6 Promise。
在我要呼叫的档案中
mongoose.connect:
mongoose.Promise = global.Promise;mongoose.connect('mongodb://10.7.0.3:27107/data/db');[EDIT: Thanks to @SylonZero for bringing up a performance flaw in my answer.
Since this answer is so greatly viewed, I feel a sense of duty to make this
edit and to encourage the use of
bluebirdinstead of native promises. Please
read the answer below this one for more educated and experienced details. ]



