What Is The Use Case Of Reference Type In Firestore Document And How To Use It Specially In An Android App?
Solution 1:
If you are storing the following document reference in the database:
/Users/OctUsers/1stWeekUsers/OlCvJFfWZeAlcttdlgzz/
And you want to get this:
FirebaseFirestore.getInstance().collection(collectionPath).document(documentPath).collection(collectionPath).document(documentPath)
You can symply rewrite it like this:
FirebaseFirestore.getInstance().document("/Users/OctUsers/1stWeekUsers/OlCvJFfWZeAlcttdlgzz/");
Remember, the most important part in a DocumenetReference
object is the string path. If you want to get that String representation, use DocumentReference's getPath() method for that.
Furthermore, if you need to deserialize that path String back into a DocumentReference
object, simply use FirebaseFirestore.getInstance().document(path).
Solution 2:
When you query for a document contains a reference type field, the field will show up in a DocumentSnapshot on an Android client as a DocumentReference type object. You can treat this just like any other DocumentReference that you build on your own. You can call get()
on it to get the referred document a you would normally. You don't have to do anything to parse the path to the document (unless you want to).
Post a Comment for "What Is The Use Case Of Reference Type In Firestore Document And How To Use It Specially In An Android App?"