Firestore文档中引用类型的用例是什么?如何在Android应用程序中特别使用它? [英] What is the use case of reference type in Firestore Document and how to use it specially in an android app?

查看:71
本文介绍了Firestore文档中引用类型的用例是什么?如何在Android应用程序中特别使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Android应用中,如果我通过获取文档的引用类型字段的值来获取文档路径,那我该怎么称呼它?因为我要获取的参考路径类似于/Users/OctUsers/1stWeekUsers/OlCvJFfWZeAlcttdlgzz/,而检索Firestore文档的方法类似于 FirebaseFirestore.getInstance().collection(collectionPath).document(documentPath).collection(collectionPath).document(documentPath),依此类推.我该如何遍历引用路径以获取要在Firestore DocumentReferece#get方法中使用的每个collectionPath和documentPath?

In my Android app, if I get the document path by getting the value of reference type field of a document then how am I going to call it? Because the reference path I'm going to get would be something like /Users/OctUsers/1stWeekUsers/OlCvJFfWZeAlcttdlgzz/ and method for retrieving a Firestore document is something like FirebaseFirestore.getInstance().collection(collectionPath).document(documentPath).collection(collectionPath).document(documentPath) and so on. How am I going to iterate over reference path for getting every collectionPath and documentPath to be used in the Firestore DocumentReferece#get method?

有人在他们的Firestore数据库中实际使用过这种引用字段类型,然后请删除屏幕截图以让我们知道更多此用例吗?

Has anyone actually used this reference field type in their Firestore database then please drop the screenshot for letting us know more use cases of this?

推荐答案

如果要在数据库中存储以下文档参考:

If you are storing the following document reference in the database:

/Users/OctUsers/1stWeekUsers/OlCvJFfWZeAlcttdlgzz/

您想得到这个:

FirebaseFirestore.getInstance().collection(collectionPath).document(documentPath).collection(collectionPath).document(documentPath)

您可以像这样将其重写:

You can symply rewrite it like this:

FirebaseFirestore.getInstance().document("/Users/OctUsers/1stWeekUsers/OlCvJFfWZeAlcttdlgzz/");

请记住,DocumenetReference对象中最重要的部分是字符串路径.如果要获取该String表示形式,请使用DocumentReference的 getPath()方法.

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.

此外,如果您需要将该路径字符串反序列化回DocumentReference对象,只需使用

Furthermore, if you need to deserialize that path String back into a DocumentReference object, simply use FirebaseFirestore.getInstance().document(path).

这篇关于Firestore文档中引用类型的用例是什么?如何在Android应用程序中特别使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆