如何获取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
发布评论