There is no way to fetch just one field from a Firebase document (https://stackoverflow.com/a/48312562/1896015).
You need to fetch the whole document, which is done asynchronously and then handle the received response, which contains the whole document data.
You also fetch the document from the collection which in this case is user
which makes the whole path user/{email}
.
From your code example this would probably look like this:
private fun getPic() {
val docRef = db.collection("user").document(auth.currentUser?.email.toString())
docRef.get()
.addOnSuccessListener { document ->
if (document != null) {
Log.d(TAG, "picUrl: ${document.data.picUrl}")
} else {
Log.d(TAG, "No such document")
}
}
.addOnFailureListener { exception ->
Log.d(TAG, "get failed with ", exception)
}
}
In this case you only log the information, but I guess you would want to return the picUrl from the function. I suggest looking in to Kotlin asynchronous functions for different ways to handle this: https://kotlinlang.org/docs/async-programming.html#callbacks