【发布时间】:2021-02-24 23:47:35
【问题描述】:
由于云 Firestore 中没有“移动”或“重命名”命令,我每天早上 6 点(英国时间)尝试将所有文档从一个集合复制到另一个集合。到目前为止,我已经想出了这段代码,但不确定如何获取 resID,然后在将原始文档保存在另一个集合中后将其删除:
exports.scheduledFunctionCrontab = functions.pubsub.schedule('0 6 * * *')
.timeZone('Europe/London') // Is this correct?
.onRun((context) => {
var dateObj = new Date();
var month = dateObj.getUTCMonth() + 1; //months from 1-12
var day = dateObj.getUTCDate();
var year = dateObj.getUTCFullYear();
console.log(`This function ran at ${Date.now}!`);
db.collection("Restaurants/${**resID**}/openorders").get().then(query => {
query.forEach(function(doc) {
var promise = firestore.collection("Restaurants/${**resID**}/closed/${year}/${month}/${day}/closed).doc(doc.data().orderID).set(doc.data());
// How I delete this document here?
});
})
.catch((error)=>{
console.log('Failure:', e);
console.log(`This function ran with ERROR at ${Date.now}!`);
});
return null;
});
【问题讨论】:
-
您在寻找
doc.ref.delete()吗? -
您想将所有日常文档转移到另一个集合吗?
-
@FrankvanPuffelen 也许他正在寻找如何获得
resId -
谢谢。是的,我正在研究如何在许多 redID 之间进行迭代。我试图让它变得大胆,因此他们周围的 astricks。
标签: node.js google-cloud-firestore google-cloud-functions