I have an app where a user can create a post. Users can also bookmark these posts. However, when a post author deletes his post that others may have already bookmarked, I need to also automatically delete those bookmarks that are associated to the deleted post.
Here's my data model (when a user bookmarks a post, the bookmark is saved to the user's record in a subcollection called bookmarks
:
I've written the code logic to delete a bookmark like so:
const postsQuery = await this.$fire.firestore
.collectionGroup('bookmarks')
.where('id', '==', this.post.id)
.get()
postsQuery.forEach((doc) => doc.delete())
console.log('bookmark deleted')
} catch (error) {
console.error('error deleteing post.', error)
}
Problem: I get the following console error when trying to delete the bookmark:
EditPost.vue?4144:107 error deleteing post. TypeError: doc.delete is not a function
at eval (EditPost.vue?4144:95)
at eval (prebuilt-28889c43-f8ea673b.js?f270:18228)
at eval (prebuilt-28889c43-f8ea673b.js?f270:16453)
at eval (prebuilt-28889c43-f8ea673b.js?f270:11563)
at t.inorderTraversal (prebuilt-28889c43-f8ea673b.js?f270:2801)
at t.inorderTraversal (prebuilt-28889c43-f8ea673b.js?f270:2719)
at t.forEach (prebuilt-28889c43-f8ea673b.js?f270:11562)
at t.forEach (prebuilt-28889c43-f8ea673b.js?f270:16452)
at t.forEach (prebuilt-28889c43-f8ea673b.js?f270:18227)
at _callee$ (EditPost.vue?4144:94)
How can I correctly write this delete logic? Thanks!