google-cloud-firestore - 云功能中未定义秒数?
问题描述
在过去的几天里,我的云功能运行良好——每分钟,都会在 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 云功能修复了日期错误,但未定义的秒数仍然存在。
解决方案
基本上,如果没有要更新的内容,我只需要不返回批量更新。这解决了问题。
推荐阅读
- javascript - Firestore 范围查询 - 将规则与“where”子句匹配
- java - 如何将 NumberFormat.getCurrencyInstance(Locale.US) 转换为 Double
- google-sheets - 图片无法在 Google 表格中打开
- dictionary - 在 C++ 中通过引用传递 map 并改变它的值
- java - 如何安装 1.8.0 版本的 java?(不是我的世界java)
- python - Python selenium 不可见 ram 使用率,直到它按时间达到 99%
- sql - SQL - 检查给定时间的日期
- linux - 将当前文件名回显到文本文件ubuntu?
- postgresql - Postgresql 查询 - 选择 json
- scala - (x: => Int) 和 (x: Int) 之间的区别?