【发布时间】:2020-12-29 00:52:09
【问题描述】:
我想构建一个 Firebase 函数,用于检查“Friends”集合中的“scheduled, ==, true”,然后在“Filings”集合中使用“fname”创建一个新文档。
我的 Firetore 设置如下:
Users (collection)
User IDs (documents)
|
|
Friends (collection)
Friends (documents with auto IDs)
[fname, scheduled: true/false]
|
|
Filings (collection)
Filings (documents with auto IDs)
每当我运行以下函数时,我都会收到一条错误消息,指出文档为空,即使它不是。我不明白为什么会这样。希望得到您的建议
exports.scheduledFunction = functions.pubsub.schedule('every 5 minutes').onRun(async context => {
const task = await (db.collection('friends').where('scheduled', '==', true).get());
if (task.empty) {
console.log('doc is empty');
return;
}
task.forEach(element => {
console.log(element.id, '==>' , element.data());
});
});
【问题讨论】:
标签: node.js firebase google-cloud-firestore google-cloud-functions