【发布时间】:2020-04-29 14:40:36
【问题描述】:
我知道通常我们必须提供一些东西,但实际上我对 firebase 中的功能感到迷茫,我尝试每个月执行一个功能,它从 firebase 文档中的字段获取数据,然后创建一个具有用户 ID 和另一个表中的数据的新文档。这可能吗,有人知道如何实现和理解吗?
export const helloWorld = functions.https.onRequest((request, response) => {
try {
db.collection('users').get()
.then(function(querySnapshot: any[]) {
querySnapshot.forEach(function(doc) {
const user = doc.id;
const conso = doc.data().conso_co2;
db.doc("historic"+user).add({
consommation: conso,
date: new Date()
})
});
})
.catch(function(error: any) {
console.log("Error getting documents: ", error);
});
}catch(error) {
console.log("Error getting document:", error);
}
response.send("Hello from Firebase!");
});
我放了一个Http触发器来简化调试
【问题讨论】:
标签: google-cloud-firestore google-cloud-functions