0

I am fetching a list of DocumentReference which I am fetching from firestore. It looks like this:

com.google.firebase.firestore.DocumentReference@4a69111d

However, I can't get the object using the above in the following code.

var loc = com.google.firebase.firestore.DocumentReference@4a69111d
var documentRef:DocumentReference = firestore.document(loc.toString())
            documentRef.get().addOnSuccessListener { document ->
                if (document != null) {
                    Log.d("SHARED_PREF_VM", "DocumentSnapshot data: ${document.data}")
                }
            })

Can I somehow convert com.google.firebase.firestore.DocumentReference@4a69111d to this form /cities/blr/areas/alpaca

1 Answer 1

3

That string is just the generic Java/JVM representation of an object when its implementation does not override toString(). It is mostly meaningless and useless to an application.

If you want to convert a DocumentReference to a string in order to use later as a DocumenReference, you should use the getPath() method on it. That will return a string which uniquely identifies that document. Then, you can turn that string back into a DocumentReference with firestore.document(), which.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.