简体   繁体   English

Firestore 中缺少文档

[英]Missing documents from firestore

I have a flutter app in development and I use firestore as the storage.我有一个正在开发的 flutter 应用程序,我使用 firestore 作为存储。 users (collections)-> userId(doc) -> records (collection)用户(集合)-> userId(doc) -> 记录(集合)

I am using this query:我正在使用这个查询:

FirebaseFirestore.instance.collection('users').doc(_userId).collection('records')

I notice when I test my app on simulator and test on my physical iphone, the list of documents I get from firestore are different.我注意到当我在模拟器上测试我的应用程序并在我的物理 iphone 上测试时,我从 firestore 获得的文档列表是不同的。 And on both env, I notice there are some documents are missing when I fetch from firestore.在这两个环境中,我注意到当我从 firestore 获取时缺少一些文件。 I can see the documents are in the firestore, but when I check the result of the query, I couldn't get the full list of documents in the collection.我可以看到文档在 firestore 中,但是当我检查查询结果时,我无法获得集合中文档的完整列表。 I notice I can only get the newly added documents.我注意到我只能获取新添加的文档。 But the older documents, I couldn't get them anymore.但是较旧的文件,我再也找不到了。 Anyone know where to start to debug this issue?任何人都知道从哪里开始调试这个问题? Thanks.谢谢。

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

I checked the query exception, no exception detected, the query succeeded.我检查了查询异常,没有检测到异常,查询成功。

Found out that the way I read from firebase has some problems.发现我从firebase读取的方式有问题。 I was using this to read from the subcollection:我用它来读取子集合:

FirebaseFirestore.instance.collection('users').doc(_userId).collection('records').snapshots() 

which returns a stream and I didn't listen to it properly.它返回一个 stream 而我没有正确地听它。

Changed to变成

FirebaseFirestore.instance.collection('users').doc(_userId).collection('records').get() 

which returns a future, and using await to wait this future.它返回一个未来,并使用 await 等待这个未来。 Now it works.现在可以了。

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

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