My firestore structure
Subwork Package (collection)
- UID (document)
- Subwork Registration (subcollection)
- Doc unique ID (document)
- data etc etc
- UID (document)
I have a table that displays all the documents that I have, inside the "Subwork Registration" subcollection.
//LOAD DATA TO TABLE IS SUCCESS
initializeTable() {
this.SubworkTable = [];
firestore
.collectionGroup("Subwork Registration")
.get()
.then(querySnapshot => {
querySnapshot.forEach(doc => {
this.SubworkTable.push({ ...doc.data(), id: doc.id })
})
})
}
Then, I will pick one of the docs and edit/update its content from the list of docs that shows on the table. But when I do as below, I got into an error .collectionGroup("").doc("") is not a function kind of error
data: () => ({
editedItem: {
v-model: '',
v-model: '',
// etc etc
}
})
//METHODS: {}
UpdateTable() {
var data = {
//
};
firestore
.collectionGroup("Subwork Registration")
.doc(this.editedItem.id)
.update(data)
.then(() => {
//
})
}
I do take note that we cannot update or set if we do .collectionGroup("Subwork Registration").doc() but Im not sure how to do it the right way (to edit/update document inside a subcollection).
Any advice?
To write a document in Firestore you will need to know the complete path to that document.
I recommend either keeping the DocumentReference if you can (as that already contains the entire path to the document), or alternative store the doc.ref.path for each document instead of doc.id as you do now.