Can we change the name of a collection in Cloud Firestore? I have created a collection with 200 documents. Now I want to change the name of the collection. In the Firebase console, I could not find a way to do this.
Is it possible to change a collection's name either through code or in the console. Or Is it possible to export documents from Firestore, create a new collection and then import those documents again?
Please help.
Right-click the collection in the sidebar and select Rename Collection.
You just need to get a reference to the subcollection, which you get from the DocumentReference . And on that you simply use the regular method for writing data again: firebase.google.com/docs/firestore/manage-data/add-data. If you're having a hard time making this work, update your question to show what you've tried.
It's not possible to change the names or IDs or collections or documents once they exist. All that data is immutable, for the purpose of building efficient indexes.
You could certainly read everything out, then put it all back in with new names and IDs.
You can load it then reupload it with the new name
await FirebaseFirestore.instance .collection(oldCollectionName) .get() .then((QuerySnapshot snapShot) async { snapShot.docs.forEach((element) async { await FirebaseFirestore.instance .collection(newCollectionName) .doc(element.id) .set(element.data()); }); });
Note: the above code is written for flutter, but it might help anyone with little changes.
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