I'm trying to update a field in all the docs returned by a query. The code below works but I was wondering if there's a way to accomplish this without having to loop the result of the query and running updateDoc on every item.
const query_ref = query(
collection(db, "somecollection"),
where("something_id", "==", this.something_id)
);
const snapshot = await getDocs(query_ref);
for (const doc of snapshot.docs) {
const ref = doc(db, "somecollection", doc.id);
await updateDoc(ref, {field: value});
}
Firestore doesn't support so-called update queries, where you pass the conditions and the new values in a single API call. So you'll have to indeed first execute the query, and then update each document as you do now.
Also see: