I am trying to export/import a specific sub-collection in Firestore using the beta version of the firestore export tool.
For example, if I have a setup of
I want to just get the companies collection and all of its subcollections, I was looking to do:
gcloud beta firestore export gs://my-bucket-name/fs_backups/companies --collection-ids='companies','users'
And I would get companies
, companies/{company}/users
and teams/{company}/users
.
I was trying all of these combos:
... -collection-ids='companies/{id}/users'
... -collection-ids='companies/./users'
... -collection-ids='companies/.*/users'
... -collection-ids='companies/*/users'
... -collection-ids='companies/**/users'
... -collection-ids='companies/__name__/users'
and some other ones as well, but was getting empty (but not failing) results.
Is there a notation for the collection ids to specify the subcollection that I am looking to export?
firestore(). collection("reservations/" + tripUid + "/ymuIjdvwWnOr20XWVp6gwRKtmgD2"). get() . This will get all the sub collection documents under the reservation with an held within tripUid variable and within the collection 'ymuIjdvwWnOr20XWVp6gwRKtmgD2'.
Export Firestore Query Results to JSONClick the collection in the sidebar on the left. Add Where conditions and Order by clauses. Adjust the number of documents with the Limit field, click the Run button to run your query! Click the Export Results icon as seen in the screenshot below.
A subcollection is a collection associated with a specific document. Note: You can query across subcollections with the same collection ID by using Collection Group Queries. You can create a subcollection called messages for every room document in your rooms collection: collections_bookmark rooms. class roomA.
I ran into the same problem. The issue is that at least two subcollections, in your example, have the name users
. The export functionality, when selecting specific collections/subcollections, "flattens" the data (i.e. subcollections will be exported into its own folder, as opposed to a subfolder within the parent collection). This makes subcollections with the same name ambiguous. The fix is to uniquely name subcollections and collections (this will also be helpful if you plan to later import it into BigQuery).
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