Cloud Firestore和Ionic [英] Cloud Firestore and Ionic

查看:65
本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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