【问题标题】:Is there any way to find if something exist inside the list in firebase database?有什么方法可以查找 firebase 数据库的列表中是否存在某些内容?
【发布时间】:2020-01-09 02:45:06
【问题描述】:

我在 Flutter 中使用 Firestore。我必须创建一个像 whatsapp 组这样的组,我得到组名、组货币、组管理员和成员列表,其中包括全名和电话号码,如您所见

groupadmin : "+923009399237"
groupcurrency : "USD"
groupmembers : "[
            {"fullname":"ABC",
             "phonenumber":"+923475894561"
            },
            {"fullname":"ASD",
             "phonenumber":"+922222222211"
            }
            ]"
groupname : "First Group"

我尝试过类似的方法,但它不起作用。

 Firestore.instance
    .collection('groups')
    .where("groupmember.phonenumber", isEqualTo: 090909090)
    .snapshots()
    .listen((data) {
  if (data.documents.length > 0) {
 }

有没有办法直接找到有电话号码== 0909090909的成员的组。请帮助我。

【问题讨论】:

    标签: json firebase dictionary flutter google-cloud-firestore


    【解决方案1】:

    值得注意的是,您也可以将 exists 添加到您的 Firestore 规则中。这样,您可以调用依赖于现有数据的 Firebase 函数,然后通过将内容放在 try/catch 中来安全地处理成功/错误。请注意,exists 算作 Firestore 读取(出于计费目的)。

    例如 allow create: if exists(/databases/$(database)/documents/users/$(request.auth.uid))

    见:https://firebase.google.com/docs/firestore/security/rules-conditions

    【讨论】:

      【解决方案2】:

      使用属性exists

       Firestore.instance
          .collection('groups')
          .where("groupmember.phonenumber", isEqualTo: 090909090)
          .snapshots()
          .listen((data) {
        if (data.exists) console.log("Yeah !");
       }
      

      另请参阅:What's the best way to check if a Firestore record exists if its path is known?

      请在发帖https://firebase.google.com/docs/firestore之前阅读文档

      【讨论】:

      猜你喜欢
      • 2016-10-22
      • 2020-01-31
      • 1970-01-01
      • 1970-01-01
      • 2021-08-11
      • 2013-04-02
      • 2018-08-15
      • 2019-08-21
      • 2011-10-11
      相关资源
      最近更新 更多