云功能:如何将Firestore Collection复制到新文档? [英] Cloud Functions: How to copy Firestore Collection to a new document?
问题描述
我想在使用云功能的事件中在Firestore中制作一个集合的副本
I'd like to make a copy of a collection in Firestore upon an event using Cloud Functions
我已经有这个代码迭代集合并复制每个集合document
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?
推荐答案
目前,没有。使用云功能循环遍历每个文档,然后使用指定的数据将新文档设置到不同的集合是唯一的方法。也许这会成为一个很好的功能要求。
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.
我们在谈论多少份文件?对于像10,000这样的东西,它只需要几分钟,顶部。
How many documents are we talking about? For something like 10,000 it should only take a few minutes, tops.
这篇关于云功能:如何将Firestore Collection复制到新文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!