[英]How would I get all data from firestore document?
在你告訴我閱讀文檔之前,我已經閱讀了。 我已經嘗試過那里的例子,但我還沒有讓它工作。
我只是想從我的數據庫的靜音部分獲取所有數據,並能夠檢查它們是否仍然處於靜音狀態。 (基本上我需要獲取他們的 UserId、公會 ID、靜音開始和靜音結束數據。)
從我嘗試過的文檔中:
const mutedDB = db.collection('muted');
const queryRef = mutedDB.where('stillMuted', '==', true);
console.log(queryRef)
和
const mutedDB = db.collection('muted');
const snapshot = mutedDB.where('stillMuted', '==', true).get();
if (snapshot.empty) return console.log('None')
snapshot.forEach(doc => {
console.log(doc.id, '=>', doc.data());
});
^ 返回錯誤 ^
我不確定我是否做對了,如果有辦法解決/解決這個問題,請告訴我!
get()
返回一個產生 DocumentSnapshot 的承諾。 它本身不返回 DocumentSnapshot。 您需要等待承諾以通常的 JavaScript 方式實現:
const promise = mutedDB.where('stillMuted', '==', true).get();
promise.then(snapshot => {
if (snapshot.empty) {
console.log('None');
return;
}
snapshot.forEach(doc => {
console.log(doc.id, '=>', doc.data());
});
}
這在您鏈接的文檔中有詳細說明,因此我實際上仍然建議您返回並再次研究文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.