Firebase 如果Flatter应用程序中没有firestore数据库集合,如何检查文档是否存在?

Firebase 如果Flatter应用程序中没有firestore数据库集合,如何检查文档是否存在?,firebase,flutter,dart,google-cloud-firestore,Firebase,Flutter,Dart,Google Cloud Firestore,如何在Flatter应用程序中检查firestore集合中是否存在文档? 我尝试了各种已经可用的示例,但它们似乎已被弃用。请告知解决方案 DocumentReference ref2 = Firestore.instance.collection("users").document(currentUserID); 要检查文档是否存在,需要使用用于从文档检索数据的get()方法,然后可以使用属性exists: Firestore.instance .collection(

如何在Flatter应用程序中检查firestore集合中是否存在文档? 我尝试了各种已经可用的示例,但它们似乎已被弃用。请告知解决方案

DocumentReference ref2 = Firestore.instance.collection("users").document(currentUserID);

要检查文档是否存在,需要使用用于从文档检索数据的
get()
方法,然后可以使用属性
exists

    Firestore.instance
        .collection("users")
        .document(currentUserID)
        .get()
        .then((doc) {
      if(doc.exists) {
        print("exists");
      } else {
        print("doesnt exists");
      }
    });

在堆栈溢出方面,展示和解释哪些尝试没有按预期的方式工作是很有帮助的。我们需要能够看到你是否可能做错了什么,这样才能纠正它。常用的检查文档是否存在的方法并没有被弃用,它已经使用了很长一段时间了。@PeterHaddad done