Cloud Firestore and Ionic

2019-08-23 02:57发布

问题:

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)