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

前端 未结 3 1449
余生分开走
余生分开走 2020-12-16 19:11

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

3条回答
  •  [愿得一人]
    2020-12-16 19:14

    There is no fast way at the moment. I recommend you rewrite your code like this though:

    import { firestore }  from "firebase-admin";
    async function copyCollection() {
        const products = await firestore().collection("products").get();
        products.forEach(async (doc)=> {
            await firestore().collection(uid).doc(doc.get('barcode')).set(doc.data());
        })
    }
    

提交回复
热议问题