Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving cloud firestore collection

I have a scenario in which I want to move my top level, in other words first, collection to the third level. Is the only way to go about this to use third party import-export software with manipulation to do this, or is there a firestore feature that I am missing? All help will be greatly appreciated.

TopLevel>Documents>ThirdLevel, where top level is the first collection in the db. Just to give a better picture of what I am trying to say.

like image 432
augustovandyk Avatar asked Apr 10 '18 13:04

augustovandyk


People also ask

How do I change my firestore cloud location?

After you set your project's default GCP resource location, you cannot change it. If you set up Cloud Firestore or Cloud Storage, you're prompted to select your project's default GCP resource location in the Firebase console workflow.

Does cloud firestore location matter?

Before you use Cloud Firestore, you must choose a location for your database. To reduce latency and increase availability, store your data close to the users and services that need it. This location setting is your project's default Google Cloud Platform (GCP) resource location.

How do I move files from one collection to another in Firebase?

Create a copy of the source document in the target collection, i.e. read it from the source collection, get the document fields and create a new document in the target collection with these fields, and then; Delete the document from the source collection.


2 Answers

Firestore has no ability to move collections or documents. Instead, you can copy documents. You'll have to write code to read the contents of a document, then write those contents to a document in a new location, then delete the original document.

like image 85
Doug Stevenson Avatar answered Sep 20 '22 00:09

Doug Stevenson


I know it's an old question, but just in case someone else needs this. It's now possible using google's cloud shell. Details available in this link: https://firebase.google.com/docs/firestore/manage-data/export-import

You have two options to export specific collections, modify them, then import them, or export the whole bucket, then import it back. As I understood you can't mix the operations for example export all and import specific collections.

Note: I believe you'll be charged for the read and write of all documents exported and imported. And billing must be activated.

like image 27
aldobaie Avatar answered Sep 18 '22 00:09

aldobaie