Q:

How to query Firebase Firestore Reference data type?

I'm using the Firestore reference data type to store a reference to a User as shown in the screenshots below

User reference

Users collections

When I try to query this data, I get a ClassCastException (I tried to cast to a String just for the sake of it).

Code

//.. this function reads data from DocumentSnapshot
//.. and converts to an Organization
private fun DocumentSnapshot.toOrganization(): Organization {
  //.. some code
      (this.data["members"] as ArrayList<HashMap<String, Any>>).map { toOrgMember(it) })
  //.. more code
}

fun toOrgMember(map: Map<String, Any>): OrgMember {
  //map["user"] as String throws ClassCastException. Refer first screenshot
  return OrgMember(map["id"] as Long, UserRef(map["user"] as String), map["type"] as String,
      asJobTitlesList(map["jobTitles"] as String))
}

Stacktrace

10-14 20:31:17.503 15569-15569/com.a.b W/System.err: Caused by: java.lang.ClassCastException: com.google.android.gms.internal.zzegf cannot be cast to java.lang.String
10-14 20:31:17.504 15569-15569/com.a.b W/System.err:     at feature.model.core.CoreUtilsKt.toOrgMember(CoreUtils.kt:28)
10-14 20:31:17.504 15569-15569/com.a.b W/System.err:     at feature.model.organization.OrgRemoteKt.toOrganization(OrgRemote.kt:55)

To what class should I cast the reference data type? (com.google.android.gms.internal.zzegf seems like an internal class which shouldn't be used)
As of now, I didn't find any example in the docs for a reference type.
Any help would be appreciated.

A:

Firestore returns a DocumentReference when getting a reference from your collections. If changing the cast to DocumentReference doesn't work, keep track of this issue.

