【发布时间】:2019-11-27 14:30:07
【问题描述】:
只有在短时间内多次调用该函数时才会出现此错误,偶尔会调用一次。
从其他回复中,它建议返回 null 作为 Firebase 云函数的 Promise。每次创建新文档时,都会在 Firebase 云函数中调用此函数。有什么想法吗?
function createMilestone(path : String){
var reg = "[^£]*£[^£]*";
const uid = path.match(reg);
if (uid){
let ref = db.collection('caseStatus').doc(path).collection("0").doc("0")
let ref1 = db.collection('caseStatus').doc(path).collection("0").doc("1")
let ref2 = db.collection('caseStatus').doc(path).collection("0").doc("2")
let ref3 = db.collection('caseStatus').doc(path).collection("0").doc("3")
let ref4 = db.collection('caseStatus').doc(path).collection("0").doc("4")
let ref5 = db.collection('caseStatus').doc(path).collection("0").doc("5")
let ref6 = db.collection('caseStatus').doc(path).collection("0").doc("6")
let ref7 = db.collection('caseStatus').doc(path).collection("0").doc("7")
let ref8 = db.collection('caseStatus').doc(path).collection("0").doc("8")
let ref9 = db.collection('caseStatus').doc(path).collection("0").doc("9")
batch.set(ref ,arrayMilestones[0]);
batch.set(ref1, arrayMilestones[1]);
batch.set(ref2, arrayMilestones[2]);
batch.set(ref3, arrayMilestones[3]);
batch.set(ref4, arrayMilestones[4]);
batch.set(ref5, arrayMilestones[5]);
batch.set(ref6, arrayMilestones[6]);
batch.set(ref7, arrayMilestones[7]);
batch.set(ref8, arrayMilestones[8]);
batch.set(ref9, arrayMilestones[9]);
batch.commit().then(function () {
console.log("imported milestones")
return null
});
}
【问题讨论】:
-
云函数回调必须返回一个仅在该函数中的所有异步工作完成后才解析的承诺。仅仅在承诺上调用
then是不够的。 firebase.google.com/docs/functions/terminate-functions -
能否包含错误跟踪?
标签: node.js firebase google-cloud-firestore google-cloud-functions