Flutter Firestore查询中是否可以使用通配符? [英] Is wildcard possible in Flutter Firestore query?
问题描述
我的目标是从聊天/$ chattype/room/{roomID}/message"路径中流式传输数据库中的所有消息,我需要在其中查询包含文档的所有消息,并在其中包含字符串"user1"它,而无需明确指定房间ID.似乎无法使它与通配符一起使用,但是..是否可以从说"chat/$ chattype/room/"进行查询?
My goal is to stream all messages in the database from the path 'chat/$chattype/room/{roomID}/message' where I need to query all messages that has a document with a string that has 'user1' in it, without explicitly specifying the rooms id. Can't seem to get it working with an wildcard, but.. is it possible to query from say: 'chat/$chattype/room/' instead?
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) {
...
推荐答案
The only way to query multiple collections is with a collection group query, which queries all collections with a given name.
所以:
_firestore
.collectionGroup('message')
.where("reciever", isEqualTo: "user1")
.snapshots(),
另请参阅Flutter参考文档以获取 collectionGroup()
.
Also see the Flutter reference documentation for collectionGroup()
.
这篇关于Flutter Firestore查询中是否可以使用通配符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!