Is it possible in Firestore to update a document in a collection group?
For example, if I only have the doc id, can I do something like this:
const player = firebase.db.collectionGroup("players").doc(playerId);
player.update(...);
Or do I need the full path to the document in order to update it?
The code you're showing isn't possible because collectionGroup() returns a Query object, and doc() isn't a method on that. You will have to query the collection group to find the document you want, then delete it as a separate operation. Also note that it's entirely possible for there to be multiple documents with the same ID within a collection group, as the group spans any number of subcollections.
Keep in mind that a query on a collection group can't filter all of the documents based on document a document ID. Typically people get around this by writing the ID of the document in a field of each document, then using that field as a filter on the collection group query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With