【问题标题】:Google Cloud Function - storage trigger complains about returning undefinedGoogle Cloud Function - 存储触发器抱怨返回未定义
【发布时间】:2019-02-22 16:40:32
【问题描述】:

我有一个带有存储触发器的云函数,我知道我需要返回 promise 以正确结束我所做的函数,但我仍然在控制台中收到警告说“函数返回未定义、预期的 Promise 或值”。

exports.elementChange = functions.storage.object().onFinalize((object) => {

    var element = {
        name: object.name,
        time: object.updated
    }


    db.collection('elements').doc(object.name).set(element)
    .then(()=> {
        return db.collection('elements').get()
    })
    .then((snapshot) => {
        return db.collection('stats').doc('elementCount').update({elementCount : snapshot.size});   
    })
    .catch(err => console.log('Error when finalise element: '+ err)) 
})

【问题讨论】:

    标签: google-cloud-firestore google-cloud-functions


    【解决方案1】:

    你实际上并没有从你的函数中返回一个承诺。将关键字return 放在db.collection(...) 之前。

    【讨论】:

      猜你喜欢
      • 2022-08-16
      • 1970-01-01
      • 2020-08-21
      • 1970-01-01
      • 2020-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多