我想建立一个Firebase Function,检查“ 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());
});
});
您的friends
收藏集嵌套在users
文档下。您的db.collection('friends')
代码仅访问顶级friends
集合,而顶级集合可能不存在。
要访问所有friends
集合,请使用:
db.collectionGroup('friends').where('scheduled', '==', true).get()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句