android - 在 Firestore Kotlin 中创建文档链接?
问题描述
我在该用户中创建了一个应用程序,该用户可以为我在firestore中创建一个集合的页面添加书签
UserList(collection)
-> UserIdgenerated(document)
-> profile(sub-collection)
-> fav(sub-collection)
-> service_page (document)
-> details
我得到了另一个(比如说第二个收藏)收藏
service(collection)
-> service_page(document)
-> details
现在我想为第二个集合文档添加书签并在片段中显示书签。 我的解决方案是将 service_page 详细信息复制到 userList fav 集合
问题有没有办法通过创建第二个收藏文档链接来创建收藏夹?
解决方案
您可以将对该集合的引用直接存储到 Firestore 中,然后.get()
在需要时调用以检索文档。在下面的示例中,我会将引用推送到数组中,您可以使用映射将引用包含在您可能拥有的任何其他数据中。
val userID = Firebase.auth.currentUser.uid
db.collection("UserList/$userID/fav")
.document("service_page")
.update("Bookmarks", FieldValue.arrayUnion(db.doc("service/service_page"))
.addOnSuccessListener { Log.d(TAG, "DocumentSnapshot successfully written!") }
.addOnFailureListener { e -> Log.w(TAG, "Error writing document", e) }
推荐阅读
- java - 如何在 Java Web 应用程序中捕获公式并支持公式评估
- raspberry-pi3 - 带屏幕的树莓派上的 Android Things 1.06
- javascript - 是否可以“暂停”发送消息以检查它?
- python - 如何将 NumPy 链接到 Eigen3、OpenBLAS、GotoBLAS2、ATLAS?
- express - Passport JWT 使用 cookie 进行身份验证
- android - Android:热点手机和使用它的手机上的数据使用量之间的差异
- c++ - 如何访问 QNetworkReply->readAll()?
- php - phpexcel下载显示病毒内容警告
- jboss - WFLYCTL0180:缺少/不可用依赖项和反射信息错误的服务
- php - 在wordpress中通过functions.php将js添加到特定页面