当我想要获取子集合时遇到问题。 有人可以帮我吗?
firestore 结构:
questions(collection) -> curretUser.id(doc) -> questions(collection) -> questionIDautoCreated(doc)-> {title: "", description: "" }
然后我尝试获取数据:
return (dispatch) => {
firebase.firestore().collection('questions').doc(currentUser.uid)
.collection('questions').get()
.then((documentSnapshot) => {
const value = documentSnapshot.data();
console.log('Value Succeed : ');
console.log(value);
});
};
错误:
可能未处理的 Promise 拒绝 (id:0) 类型错误:documentSnapshot.data 不是函数
谢谢
最佳答案
因为集合不是 DocumentSnapshot
,它是 QuerySnapshot
。集合包含数据列表,它不是实际文档。
如果您查看 firestore 文档 here .可以看到查询集合时,应该:
querySnapshot.forEach(function(doc) {
console.log(doc.id, " => ", doc.data());
});
异常说明了一切,你收到的对象不是你期望的。
return (dispatch) => {
firebase.firestore().collection('questions').doc(currentUser.uid)
.collection('questions').get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
console.log(doc.id, " => ", doc.data());
});
});
};
关于javascript - 未检索 React Native Firestore 子集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49363765/