I attempted to implement the following method:
deleteMessages(){
this.firestore.collection("MESSAGES")
.get()
.then(res => {res.forEach(element => {element.ref.delete();});
});
}
However, I encountered the following error:
Property 'then' does not exist on type 'Observable<QuerySnapshot>'.
So, I decided to try this instead:
deleteTheMessages() {
const messagesCollection= this.firestore.collection<Message>('MESSAGES').get();
messagesCollection.toPromise().then((snapshot) => {
snapshot.forEach((doc) => doc.ref.delete());
});
}
Then, when I attempted to ng build, I received this error message:
error: src/app/messages.service.ts:37:9 - error TS2532: Object is possibly 'undefined'.
37 snapshot.forEach((doc) => doc.ref.delete());
with ~~~~~~~~ under the word snapshot.
Since I couldn't resolve either issue, I would greatly appreciate any suggestions you may have.