如果未找到 Firestore 中的搜索查詢,我正在嘗試使用 console.log “Not Found”。目前,我正在使用以下內容執行查詢,該查詢查看所有檔案中的電子郵件 =“[email protected]”。
如果檔案包含我正在搜索的內容,這很好用,但如果沒有找到任何東西,我就無法將它發送到 console.log
db.collection("test").where('email', '==', "[email protected]").get()
.then(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
console.log(doc.data())
});
}).catch(function (error) {
console.log("Error getting document:", error);
});
uj5u.com熱心網友回復:
如果沒有找到匹配的檔案,那么QuerySnapshot的empty屬性將是:true
db.collection("test").where('email', '==', "[email protected]").get().then(qSnap => {
if (qSnap.empty) {
console.log("Not found")
} else {
// proceed
}
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/334742.html
