【问题标题】:How to get all documents in a firestore subcollection如何获取firestore子集合中的所有文档
【发布时间】:2019-09-18 06:16:02
【问题描述】:

我目前有一个类似于 this 的 Firestore:

Collection('machines').doc(*machineID*).collection('reports').doc(*multiple docs reports*)

我正在使用Vue,我正在尝试获取“报告”集合中的所有文档。

我可以获得一份报告

reports: firebase.firestore()
  .collection('machine')
  .doc('machine_01')
  .collection('report')
  .doc('report_05')

但我无法获得整个子集合

reports: firebase.firestore()
  .collection('machine')
  .doc('machine_01')
  .collection('report')

这可能吗?我是新手,所以这可能是一个愚蠢的问题。

谢谢!

编辑 我在控制台中收到的错误消息是:

index.cjs.js?e89a:350 Uncaught (in promise) FirebaseError: Missing or insufficient permissions.
    at new FirestoreError (webpack-internal:///./node_modules/@firebase/firestore/dist/index.cjs.js:350:28)
    at JsonProtoSerializer.fromRpcStatus (webpack-internal:///./node_modules/@firebase/firestore/dist/index.cjs.js:14844:16)
    at JsonProtoSerializer.fromWatchChange (webpack-internal:///./node_modules/@firebase/firestore/dist/index.cjs.js:15335:44)
    at PersistentListenStream.onMessage (webpack-internal:///./node_modules/@firebase/firestore/dist/index.cjs.js:11305:43)
    at eval (webpack-internal:///./node_modules/@firebase/firestore/dist/index.cjs.js:11234:30)
    at eval (webpack-internal:///./node_modules/@firebase/firestore/dist/index.cjs.js:11274:28)
    at eval (webpack-internal:///./node_modules/@firebase/firestore/dist/index.cjs.js:1634:20)

我不确定权限,我无权访问它们,但如果是权限问题,我很困惑我可以从集合中获取单个文档,但找不到方法获取所有文件

【问题讨论】:

标签: javascript firebase google-cloud-firestore


【解决方案1】:

因为您收到Missing or insufficient permissions 错误。看起来用户无权访问您的数据库信息;因此,我会尝试执行以下操作:

// Allow read/write access on all documents to any user signed in to the application

service cloud.firestore {
  match /databases/{database}/documents {
     match /{document=**} {
      allow read, write: if request.auth.uid != null;
     }
  }
}

更多信息here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-03
    • 2021-05-09
    • 2023-03-08
    • 2018-07-01
    • 2021-02-16
    • 1970-01-01
    相关资源
    最近更新 更多