簡體   English   中英

如何在Firestore子集合中獲取所有文檔

[英]How to get all documents in a firestore subcollection

我目前有一個看起來像這樣的消防站:

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)

我不確定權限,我無法訪問它們,但是如果是權限問題,我很困惑,我只能從集合中獲取單個文檔,但是找不到找到所有文檔的方法文件

由於您收到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;
     }
  }
}

更多信息在這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM