简体   繁体   English

Firestore 返回根目录中的所有文档

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

At the root of my firestore db I have a 'users' and 'accounts' collections. Whenever I try to return all documents in either of those collection I get an error (there is definitely data there):在我的 firestore 数据库的根目录下,我有一个“用户”和“帐户”collections。每当我尝试返回这些集合中的任何一个中的所有文档时,我都会收到错误消息(那里肯定有数据):

Uncaught (in promise) FirebaseError: Null value error.未捕获(承诺)FirebaseError:Null 值错误。 for 'list' @ L59, Null value error.对于“列表”@ L59,Null 值错误。 for 'list' @ L63, Null value error.对于“列表”@ L63,Null 值错误。 for 'list' @ L76对于“列表”@ L76

Code to produce above error:产生上述错误的代码:

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

  const querySnapshot = await getDocs(query);

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

If I try and return all documents from any sub collection it works fine:如果我尝试从任何子集合中返回所有文档,它工作正常:

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

  const querySnapshot = await getDocs(query);

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

Any ideas why this would be, am I querying wrong?任何想法为什么会这样,我查询错了吗? Could it be something to do with firestore rules?这可能与 firestore 规则有关吗?

Ta.塔。

In case anyone else has this issue I've found the cause.如果其他人遇到此问题,我已经找到了原因。

I just disabled all rules in firestore.rules (created by someone else) and added a general rule to access all documents if authenticated:我只是禁用了 firestore.rules 中的所有规则(由其他人创建)并添加了一个通用规则以在经过身份验证后访问所有文档:

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

This then stopped the error and listed all documents.然后这停止了错误并列出了所有文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM