返回的功能未定义和承诺在功能中未定义firebase
这是我的第一个firebase功能,它给了我很多头号:)目的是每24小时从收集用户那里更新所有文档的计数字段。
async function clearCountField() {
console.log("Clearing count task start point.");
const userSnapshots = db.collection('users').where('count', '!=', '').where('nou', '==', false).get().then(snapshot => {
const promises = [];
snapshot.forEach(doc => {
promises.push(doc.ref.update({ 'count': '' }));
});
});
return Promise.all(promises)
}
export const ClearCountField24h = functions.pubsub.schedule('0 0 * * *')
.timeZone('Europe/Bucharest') // timezone
.onRun((context) => {
const promise = clearCountField().then(resolve,reject);
});
我做错了什么?
This is my first firebase function and it gives me a lot of headic :) The purpose is to update the count field from all documents from collection users every 24 hours.
async function clearCountField() {
console.log("Clearing count task start point.");
const userSnapshots = db.collection('users').where('count', '!=', '').where('nou', '==', false).get().then(snapshot => {
const promises = [];
snapshot.forEach(doc => {
promises.push(doc.ref.update({ 'count': '' }));
});
});
return Promise.all(promises)
}
export const ClearCountField24h = functions.pubsub.schedule('0 0 * * *')
.timeZone('Europe/Bucharest') // timezone
.onRun((context) => {
const promise = clearCountField().then(resolve,reject);
});
what do I do wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
循环中创建的承诺永远无法解决,因为
promise.all()
正在查询完成之前返回。这样修复它:您的导出功能中的
然后
是多余的。只需从clearcountfield()
返回承诺The promises created in the
forEach
loop are never resolved becausePromise.all()
is being returned before the query completes. Fix it like this:The
then
in your export function is superfluous. Just return the promise fromclearCountField()
更改以下内容:
对此:
使一个问题消失了...但是在测试函数时,
错误:ReferenceError:未定义的承诺
仍然保留...Changing the following:
To this:
Made one issue go away... but when testing the function the
Error: ReferenceError: promises is not defined
still remains...