云功能未定义秒?

时间:2018-07-23 19:28:59

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

在过去的几天中,我的云功能运行良好-每分钟,都会在firestore中查询旧帖子,然后将其删除,例如:

exports.hourly_job = functions.pubsub.topic('hourly-tick').onPublish((change,context) => {
    const currentTime = Date.now()
    const getPostsForDate = admin.firestore().collection('posts').where('timeOfDeletion', '<', currentTime)
    return getPostsForDate.get().then(snapshot => {
        const updates = {}
        const batch = admin.firestore().batch()
        snapshot.forEach((doc) => {
            var key = doc.id
            console.log(key)
            const convos =  admin.database().ref('/convoID/' + key).once('value', (snapshot) => {
                 if (snapshot.exists){
                     const convos = snapshot.val()
                     snapshot.forEach((child) => {
                        updates["conversations/" + child.key] = null
                        updates["messages/"+ child.key] = null
                        updates["convoID/"+ child.key] = null
                    })
                 }
             })
             updates["/convoID/"+ key] = null
             updates["/reveals/" + key] = null
             updates["/postDetails/" + key] = null
             const postFireStoreRef = admin.firestore().collection('posts').doc(key)
             const posterRef = admin.firestore().collection('posters').doc(key)
             batch.delete(postFireStoreRef)
             batch.delete(posterRef)
        })
        return Promise.all[admin.database().ref().update(updates), batch.commit()] 
})
})

但是,我开始收到消息:

TypeError: Cannot read property 'seconds' of null
    at Function.fromProto (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/timestamp.js:91:46)
    at _firestore.request.then.resp (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/write-batch.js:472:42)

编辑:我通过更新Firebase云功能解决了日期错误,但秒数仍然不确定。

1 个答案:

答案 0 :(得分:1)

基本上,如果没有要更新的内容,我只需要不返回批处理更新。那解决了问题。