javascript - 未检索 React Native Firestore 子集合

标签 javascript react-native google-cloud-firestore

当我想要获取子集合时遇到问题。 有人可以帮我吗?

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/

相关文章:

javascript - 错误 : Value for argument "value" is not a valid query constraint. 无法使用 "undefined"作为 Firestore 值

javascript - 传递具有自定义数据属性的函数

javascript - 如何从 Cypress 返回 Map 对象?

react native Android : Unable to display static images

react-native - React-Navigation v5 - 堆栈导航器之间的透明度

javascript - Angular Firestore : What is the correct syntax for a collection query that uses a where clause?

javascript - Angular 表达式不评估文本/ng-模板

javascript - Grunt list : Put to a subdirectory the source paths

ios - 代码推送 : How to deploy to multiple build versions of the same deployment config?

flutter - Firestore PERMISSION_DENIED