Cloud Firestore和Ionic

编程入门 行业动态 更新时间:2024-10-28 04:23:11
本文介绍了Cloud Firestore和Ionic的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何获取Cloud Firestore中存在的集合的文档ID?

How can I get the document id of a collection present in the cloud Firestore?

我试图通过

firebase.firestore().collection("collectionName").doc().id

但我没有得到适当的结果。

but I didn't get the appropriate result.

推荐答案

firebase.firestore()。collection( societies)。doc()。id,它返回的ID与社会documentId不等价

firebase.firestore().collection("societies").doc().id and it returns a id which is not equivalent to society documentId

这是正确的,因为每次使用上面的代码行时,您都会生成一个 new 文档ID,该ID永远不会与数据库中已经存在的ID相同

That's correct because everytime when you are using the above line of code, you are generating a new document id which will never be the same with one that already exist in your database.

要使用新的文档ID,首先需要生成它(就像已经做的那样),然后将其存储在变量中。有了包含该ID的变量,您可以通过将ID作为参数传递给 doc(id)函数来使用它来从数据库中获取特定文档:

In order to use a new document id, first you need to generate it (as you already do) and then store it in a variable. Having that varaible which holds that id, you can use it to get that particular document from the database by passing this id as an argument to the doc(id) function:

firebase.firestore().collection("societies").doc(this.myId)

更多推荐

Cloud Firestore和Ionic

本文发布于:2023-11-22 05:14:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616105.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Cloud   Firestore   Ionic

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!