Flutter Firestore查询中是否可以使用通配符? [英] Is wildcard possible in Flutter Firestore query?

查看:42
本文介绍了Flutter Firestore查询中是否可以使用通配符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是从聊天/$ 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆