簡體   English   中英

Firestore 返回根目錄中的所有文檔

[英]Firestore return all documents in collection at the root

在我的 firestore 數據庫的根目錄下,我有一個“用戶”和“帳戶”collections。每當我嘗試返回這些集合中的任何一個中的所有文檔時,我都會收到錯誤消息(那里肯定有數據):

未捕獲(承諾)FirebaseError:Null 值錯誤。 對於“列表”@ L59,Null 值錯誤。 對於“列表”@ L63,Null 值錯誤。 對於“列表”@ L76

產生上述錯誤的代碼:

const query = fs.query(
     fs.collection(firestore, 'accounts'),
  );

  const querySnapshot = await getDocs(query);

  querySnapshot.forEach((doc) => {
     console.log(doc.id, ' => ', doc.data());
  });

如果我嘗試從任何子集合中返回所有文檔,它工作正常:

const query = fs.query(
     fs.collection(firestore, `accounts/${accountId}`, 'sites'),
  );

  const querySnapshot = await getDocs(query);

  querySnapshot.forEach((doc) => {
     console.log(doc.id, ' => ', doc.data());
  });

任何想法為什么會這樣,我查詢錯了嗎? 這可能與 firestore 規則有關嗎?

塔。

如果其他人遇到此問題,我已經找到了原因。

我只是禁用了 firestore.rules 中的所有規則(由其他人創建)並添加了一個通用規則以在經過身份驗證后訪問所有文檔:

match /{document=**} {
  allow read, write: if request.auth != null;
}

然后這停止了錯誤並列出了所有文檔。

暫無
暫無

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

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