我尝试用这个firebase函数来更新作者。
exports.updateCourseName = functions.firestore
.document('courses/{courseId}')
.onUpdate((change, context) => {
const newValue = change.after.data().name;
const previousValue = change.before.data().name;
const course1Id = context.params.courseId;
if(newValue != previousValue){
admin
.firestore().collection("set").where("course.id", "==", course1Id)
.get()
.then((querySnapshot) => {
if (!querySnapshot.empty) {
// doc.data().author = newValue
querySnapshot.docs[0].course
.update({author : newValue
})
}
})
.catch((error) => {
console.log("Error changing Author name in courses", error);
});
}
})
我没有得到一个错误的日志,但Function returned undefined, expected Promise or value
我做错了什么?
2条答案
按热度按时间kqlmhetl1#
当所有异步工作完成时,您需要终止Cloud Function,请参阅doc。在后台触发的云函数(例如,云Firestore函数
onUpdate
触发器)必须返回异步方法调用返回的整个chain of promises。但是,我不清楚你想做什么:
什么是
course
?update()
方法是DocumentReference
方法的一种。你可能想做
piv4azn72#
错误消息非常明确,在那里:
Function returned UNDEFINED, expected Promise or value
。您显示的不完整代码片段不会返回任何内容。尝试: