How to check if the field exists in firestore?

前端 未结 2 1255
长发绾君心
长发绾君心 2021-01-23 01:16

I am checking whether the Boolean field called attending exists, however I am not sure how to do that.

Is there a function such as .child().exists()<

2条回答
  •  忘了有多久
    2021-01-23 01:38

    You can do the following:

      if(task.isSuccessful()){
        for(QueryDocumentSnapshot document: task.getResult()){
           if (document.exists()) {
              if(document.getBoolean("attending") != null){
                 Log.d(TAG, "attending field exists");
              }
            }
          }
      }
    

    From the docs:

    public boolean exists ()

    Returns true if the document existed in this snapshot.

提交回复
热议问题