我正在尝试将集合中的所有文档打印给我。但是,以下代码未执行,或者我无法进入 forEach 循环。我在 Firestore 中有一个嵌套集合。 用户//条目/uuid()/doc
const querySnapshot = await getDocs(collection(db, "eintraege"));
querySnapshot.forEach((doc) => {
// Never executed
console.log(doc.id, " => ", doc.data());
});
最佳答案
for 循环未执行,因为您使用的引用不完整。如果要查询eintraege
子集合,那么你必须使用以下引用:
const querySnapshot = await getDocs(collection(db, "users", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5230373c387c7c7c12353f2a7c3637" rel="noreferrer noopener nofollow">[email protected]</a>" "eintraege"));
哪里users
是顶级集合,"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dab8bfb4b0f4f4f49abdb7a2f4bebf" rel="noreferrer noopener nofollow">[email protected]</a>"
是文档的 ID,eintraege
是子集合。
关于javascript - 输出嵌套集合中的所有文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77330384/