Cloud Firestore and Ionic

六月ゝ 毕业季﹏ 提交于 2019-12-13 03:33:17

问题


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

I tried to get it by using the

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

but I didn't get the appropriate result.


回答1:


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

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.

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)


来源:https://stackoverflow.com/questions/53262704/cloud-firestore-and-ionic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!