I'm trying to check whether a document in the firestore exists. I copied an exact location of the document (col3) from the firestore console, so it must correct.
The document.exists() returns false despite the document being saved in the database. I followed Google guide from this site.
I've set the break point and checked the DocumentSnapshot object, but it very hard to follow e.g zza, zzb, zzc...
private fun nameExists(userId: String, colName: String): Boolean{
val nameExists = booleanArrayOf(false)
val docRefA = fbDb!!.document("users/X9ogJzjJyOgGBV0kmzk7brcQXhz1/finalGrades/col3")
val docRefB = fbDb!!.collection("users")
.document(userId)
.collection("finalGrades")
.document(colName)
docRefA.get().addOnCompleteListener { task ->
if (task.isSuccessful) {
val document = task.result
if (document.exists()) {
nameExists[0] = true
}else{
Log.d(TAG, "no such document")
}
} else {
Log.d(TAG, "get failed with ", task.exception)
}
}
return nameExists[0]
}