har*_*B10 1 dart firebase flutter google-cloud-firestore
我正在尝试在 Firebase 中查询子集合,但我总是得到一个空列表...
这是我的查询:
Firestore.instance.collection('messages').where('idFrom', isEqualTo: userID).snapshots();
Run Code Online (Sandbox Code Playgroud)
我知道我在这里有另一个子集合的子集合。
/messages/RWzG98s92mVTZniofez6YoYsNhA3-tT2Q16n1FMZoTNZQOejtWuJdCmD2/RWzG98s92mVTZniofez6YoYsNhA3-tT2Q16n1FMZoTNZQOejtWuJdCmD2/1579394957103
Run Code Online (Sandbox Code Playgroud)
我的问题是如何查询这些类型的模型?
由于 Firstore 查询总是浅的,您必须构建到要查询的子集合的路径。
Firestore.instance
.collection('messages')
.document(...) // ID of the nested document
.collection(...). // ID of the nested subcollection
.where('idFrom', isEqualTo: userID);
Run Code Online (Sandbox Code Playgroud)
没有办法避免提供那些嵌套的 ID。如果您无法确定要查询的子集合的完整路径,您将无法访问其文档。
| 归档时间: |
|
| 查看次数: |
1679 次 |
| 最近记录: |