从逻辑上,结构上理解我应该如何使用Firebase时遇到一些问题。
我有一个目前看起来像这样的数据库:
Collection:
- Stores
Document:
- UID of user
Collection:
- Datafield1
- Datafield2
- Datafield3
- Datafield4
- etc etc etc
在我使用的应用程序中:
StreamBuilder(
stream: Firestore.instance.collection('stores').snapshots(),
builder: (context, snapshot) {
<code here>
}
),
正如所有文档和指南所建议的。
但是,这返回了我所有文档(即我的所有用户ID)的循环。我不希望这样,因为用户只能看到自己的数据。但是,如果我尝试将其更改为:
stream: Firestore.instance.collection('stores').document(uid).snapshots(),
然后给出一个错误,因为您只能循环浏览文档集合,而不能循环浏览文档集合。
因此,由于此设计根本不起作用,我想也许在数据库中添加了另一个多余的级别,使其类似于:
Collection:
- application name
Document:
- Stores
Collection:
- UID of user
Document:
- Datafield1
- Datafield2
- Datafield3
- Datafield4
- etc etc etc
试图迫使它符合可用的东西。但它也不允许您在Firebase中执行此操作,因为它仅允许三个总计级别:集合>文档>集合。而已。
因此,我的问题是,如何使用该产品仅循环浏览一组用户数据?我敢肯定,这是对这一行的简单更改:
stream: Firestore.instance.collection('stores').snapshots(),
但是我在网上找不到任何关于此的信息。
但是我建议听快照更改,然后更新所需的变量。
如果使用此:
然后执行:
Then the above should get only the data inside the
uid
document, it wont get the sub collections. If you want to access the data inside the subcollection of one user, then use the following:This will get all the documents inside the subcollection
userStore