【问题标题】:How can I check for particular value in firebase in a collection.document.collection.document() flutter dart如何在 collection.document.collection.document() 颤振飞镖中检查 firebase 中的特定值
【发布时间】:2021-05-03 07:21:43
【问题描述】:

我想检查 collection.document.collection.document() 中的某个 id 是否在 firebase flutter dart 中可用,如果是,我删除该 id,否则我将该 id 添加到数据库中。

所以我的问题是访问 id 值,我尝试了 .contains 方法,但即使该值存在,它也总是返回 false。我该如何解决这个问题

这是我的 Firestore 设计

Firestore.instance .collection('postt') .document(postsId) .collection('类型') .document();

【问题讨论】:

    标签: firebase flutter dart firebase-storage


    【解决方案1】:

    我不知道你的 Firestore 设计是什么样的,但根据你的描述,这个例子应该可以工作。

      DocumentSnapshot doc = await FirebaseFirestore.instance.collection('posst')
        .doc('postsId')
        .collection('type')
        .where('id',isEqualTo: 'your id')
        .get();
      if(doc.exists){
          // todo 
      }else{
        // todo
      }
    

    【讨论】:

    • 所以,这会检查文档是否仅存在。我是初级开发人员,帮我理解......我想检查文档中的特定 id
    • @vinchuli 我想我明白你的意思,你需要 where 子句才能在你的文档中获得特定的价值我编辑我的问题希望它会有所帮助
    • 这个大开眼界,没想到在这行,。我试一试
    猜你喜欢
    • 1970-01-01
    • 2020-08-12
    • 2018-09-10
    • 1970-01-01
    • 2020-01-12
    • 2020-11-28
    • 2022-07-20
    • 1970-01-01
    相关资源
    最近更新 更多