[英]Mongoose query returns error, but error is the result I am looking for
根據文檔: https ://mongoosejs.com/docs/promises.html您應該使用query.exec()獲得完整的承諾:
// `.exec()` gives you a fully-fledged promise
var promise = query.exec();
promise.then(function (doc) {
// use doc
});
當您像承諾一樣使用它時,
.then((doc)=>console.log(doc))
doc是實際的文檔,最終會出現錯誤
.catch(err=>console.log(err))
當您使用.then()
並且承諾被解決時,您將在then()
得到結果。
.then((result) => console.log(result))
當承諾被拒絕時,您可以捕獲以下錯誤:
.catch((error) => console.log(error))
承諾分為三個階段: resolve
, reject
和pending
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.