Firebase 检索Firestore中嵌套子集合的文档ID
我的Firebase Firestore具有以下结构:Firebase 检索Firestore中嵌套子集合的文档ID,firebase,google-cloud-firestore,Firebase,Google Cloud Firestore,我的Firebase Firestore具有以下结构: 是否可以查询第二个图像的中间列中显示的文档ID?这是我当前的查询,在我看来这是最合乎逻辑的方式。console.log返回成功消息,但数组为空: async function getListofPosts() { try{ return await useFireStore .collection('chats') .doc(`${postId}`) .collec
是否可以查询第二个图像的中间列中显示的文档ID?这是我当前的查询,在我看来这是最合乎逻辑的方式。console.log返回成功消息,但数组为空:
async function getListofPosts() {
try{
return await useFireStore
.collection('chats')
.doc(`${postId}`)
.collection('chat')
.get().then(res => {
let theMessageList = [];
res.forEach(doc => {
theMessageList.push(doc.data(), doc.id )
});
setMessageList(theMessageList);
});
}
catch {
console.log('error on getListofPosts')
}
finally {
console.log('getListofPosts worked')
}
}
非常感谢您的帮助。
干杯,马特相关问题-
“收藏”chats
和chat
下的文档似乎是空的(文档ID以斜体显示)。因此,要解决这个问题,您应该使用collectionGroup
query
return await useFireStore
.collectionGroup('chat')
.get().then(res => {
let theMessageList = [];
res.forEach(doc => {
theMessageList.push(doc.data(), doc.id )
});
setMessageList(theMessageList);
});
在使用
collectionGroup
query之前,我建议您阅读此查询及其限制-非常感谢,Muthu。我不知道Firestore认为文件是空的,谢谢你指出这一点。上面的代码仍然返回一个空数组,但我现在明白了原因。有了解决方案我会发布的。太好了!是,请在找到解决方案后更新一次。它将帮助观众!