我目前的react native/firebase的问题是在我的应用中查询我的论坛页面中每个帖子的评论。当用户进入论坛部分时,我的论坛数据库中的所有帖子都能正确加载,但当试图通过比较不同帖子的ID来获取每个帖子的评论时,react native不允许我这样做,并说:集合引用无效。集合引用必须具有奇数个段我如何修复此问题???
useEffect(() => {
async function ddd() {
let todos = []
// uid is already declared in my app and refers to the id of the post document
try {
const url = collection(db, `forums`,"comments");
const q = query(url,where("uid","==",uid);
const querySnapshot = await getDocs(q);
querySnapshot.forEach((doc) => {
// doc.data() is never undefined for query doc snapshots
console.log(doc.data());
todos.push(doc.data())
});
}
catch(E){
alert(E)
}
setData1(todos)
}
ddd()
}, [])
火库结构:
1条答案
按热度按时间xytpbqjk1#
要加载/查询特定论坛的评论,您必须在此处的路径中指定论坛ID:
如果要查询所有名为
comments
的集合,可以使用集合组查询,如下所示: