Search code examples
firebasekotlingoogle-cloud-firestorefirebaseui

How to use query .document using firebase ui


I'm using this Firebase-UI

I have Users (collection), uid (document), and array for image url.

This is my Firebase schema

How to use document query so I can get specific user and get imageUrl?

Query query = FirebaseFirestore.getInstance()
    .collection("users")
    .document(auth.currentUser!!.uid)

Error:

None of the following functions can be called with the arguments supplied. setQuery(Query, (snapshot: DocumentSnapshot) → Profile) defined in com.firebase.ui.firestore.FirestoreRecyclerOptions.Builder setQuery(Query, SnapshotParser) defined in com.firebase.ui.firestore.FirestoreRecyclerOptions.Builder setQuery(Query, Class) defined in com.firebase.ui.firestore.FirestoreRecyclerOptions.Builder

this works, but i just want to know if i can use .document

val query = FirebaseFirestore.getInstance()
        .collection("users")
        .whereEqualTo(FieldPath.documentId(), auth.currentUser!!.uid)

Solution

  • There is no way to use the following line of code:

    Query query = FirebaseFirestore.getInstance()
        .collection("users")
        .document(auth.currentUser!!.uid)
    

    Once because this is not the way you are declaring variables in Kotlin. And second because when calling document() function on a CollectionReference object it returns a DocumentRefence object and not a Query object.

    So you can simply use:

    val document = FirebaseFirestore.getInstance()
        .collection("users")
        .document(auth.currentUser!!.uid)
    

    And the document object will now of type DocumentReference.