首页 > 解决方案 > 如何在 collection.document.collection.document() 颤振飞镖中检查 firebase 中的特定值

问题描述

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

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

这是我的防火设计

Firestore.instance .collection('postt') .document(postsId) .collection('type') .document();

标签: firebaseflutterdartfirebase-storage

解决方案


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

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

推荐阅读