Reputation: 4033
I'm currently trying to react to the creation of a document inside of firestore.
The function createRequest
creates a doc within firestore, this triggers a firebase function which again creates a document (same id as previously created doc) inside of firestore but in another collection - how can I wait for this exact document to be created?
async createRequest(name: string, company: string, email: string, phone: string, message: string, products: any[]) {
await this.requests.add({name, company, email, phone, message, products});
}
this.rs.createRequest(this.name, this.company, this.email, this.phone, this.message, this.products).then(() => {
// Wait for creation of document inside of collection ('mail') with same id
});
Upvotes: 1
Views: 801
Reputation: 317467
You can simply write code to add a listener (observable) for the document that's expected to eventually exist, just like any other document listener. The listener will trigger when the document is first created, and it will receive the contents. You must know the expected ID of the document ahead of time, which it sounds like the case here.
I suspect the documentation will help you learn about how to set up an observable on a document.
Upvotes: 3