我的目标是从路径 'chat/$chattype/room/{roomID}/message' 流式传输数据库中的所有消息,在该路径中我需要查询文档中包含包含 'user1' 的字符串的所有消息,而无需查询明确指定房间 ID。似乎无法让它与通配符一起工作,但是..
是否可以通过“chat/$chattype/room/”进行查询?
Widget build(BuildContext context) {
return StreamBuilder<QuerySnapshot>(
stream: _firestore
.collection('chat/$chattype/room/{roomID}/message')
.where("reciever", isEqualTo: "user1")
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
...
查询多个集合的唯一方法是使用集合组查询 https://firebase.google.com/docs/firestore/query-data/queries#collection-group-query,它查询具有给定名称的所有集合。
So:
_firestore
.collectionGroup('message')
.where("reciever", isEqualTo: "user1")
.snapshots(),
另请参阅 Flutter 参考文档collectionGroup() https://pub.dev/documentation/cloud_firestore/latest/cloud_firestore/Firestore/collectionGroup.html.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)