is it possible to update only one document id in a firestore subcollection, I have been searching for solution but all I can find is to query all documents. if I use querySnapshot.foreach() all documents in a subcollection with the same field value gets updated. Using .where() also query all documents and not a specific id, but I am only trying to update one. I am trying to use the document id but I could not figure out how to call the id for the subcollection. Is there a way to do that?
const currentUser=firebase.auth().currentUser;
const userPost= firebase.firestore().collection('users')
.doc(currentUser.uid).collection("post");
const EditPost = async (event) => {
event.preventDefault();
await userPost
.doc() <-- here I've been trying to put the subcollection doc id
.set({
title: title,
body: body,
updatedAt: date,
}, { merge: true })
.catch((err) => {
console.log(err)
})
}
here is a sample screenshot of the firestore subcollection structure
. Currently I tried using uuidv4 so I can also create a field value of postId upon adding a new document, because I was planning on just calling the postId as a document id but it was also inside the subcollection ducument.
doc(). - Doug Stevensondoc(). You're passing nothing right now. - Doug Stevenson