【发布时间】:2019-11-12 16:52:00
【问题描述】:
我正在运行 Firestore 云功能并且输出是预期的,但在日志中我看到一个错误
函数返回未定义的、预期的 Promise 或值
我不知道为什么在我退回批次时它会这样说。我将如何删除此日志错误,以及访问文档 TYPES 以便我不能使用 ANY 类型。
export const subscriptionAdded = functions
.firestore
.document(`/User/{userId}/following/{subscriptionId}`)
.onCreate((change: any, context: functions.EventContext) => {
admin.firestore()
.collection(`/Challenge`)
.where('user_id', '==', context.params.subscriptionId).get().then((snapshot: any) => {
const batch = admin.firestore().batch();
snapshot.forEach((doc: any) => {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
let autoId = ''
for (let i = 0; i < 20; i++) {
autoId += chars.charAt(Math.floor(Math.random() * chars.length))
}
const userChallenges = admin.firestore().doc(`/Subscribed_Challenges/${context.params.userId}/myChallenges/${autoId}`)
batch.set(userChallenges, {
challegeId: context.params.subscriptionId,
subscriptionUserId: context.params.userId,
dateTime: new Date()
})
});
return batch.commit().catch((err: any) => {
console.log('Batch Error', err)
});
}).catch(err => {
console.log('Error getting documents', err);
});
})
【问题讨论】:
标签: javascript google-cloud-firestore google-cloud-functions