Reputation: 62743
I'm wondering if there's a more straightforward way to set a collection as a sub-collection in a new document. My current method is:
CollectionA
, which will be used as the sub-collectionDocA
DocA
CollectionB
in DocA
batch()
and loop through CollectionA
, using batch(set, CollectionA.doc.data())
on each doc of CollectionA
batch.commit()
to commit all the docs from CollectionA
into CollectionB
Is there a simpler way to accomplish this?
Like:
DocA.collection('CollectionB').set(CollectionA)
I've tried a few methods similar to this but CollectionA
ends up living in a single doc within CollectionB
. Instead of all the docs within CollectionA
becoming docs within CollectionB
.
Upvotes: 0
Views: 348
Reputation: 598728
There is no API to duplicate documents from one collection into another. You will have to read the documents to a client, and then write them into the target collection.
I don't think there's any faster way to do that then by copying them in batches. Note that a batch can contain no more than 500 write operations, so you may have to perform multiple.
Upvotes: 1