Cloud Functions: How to copy Firestore Collection to a new document?

自古美人都是妖i 提交于 2019-12-06 00:33:53

问题


I'd like to make a copy of a collection in Firestore upon an event using Cloud Functions

I already have this code that iterates over the collection and copies each document

    const firestore = admin.firestore()
    firestore.collection("products").get().then(query => {
        query.forEach (function(doc){
            var promise = firestore.collection(uid).doc(doc.data().barcode).set(doc.data());
        });
    });

is there a shorter version? to just copy the whole collection at once?


回答1:


Currently, no. Looping through each document using Cloud Functions and then setting a new document to a different collection with the specified data is the only way to do this. Perhaps this would make a good feature request.

How many documents are we talking about? For something like 10,000 it should only take a few minutes, tops.



来源:https://stackoverflow.com/questions/49691215/cloud-functions-how-to-copy-firestore-collection-to-a-new-document

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!