我正试着在firebase上运行一个预定的云函数。当它运行时,我在日志中看到以下错误:
Error: Process exited with code 16
at process.<anonymous> (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:237:22)
at process.emit (events.js:400:28)
at process.emit (domain.js:470:12)
at process.exit (internal/process/per_thread.js:169:15)
at Object.sendCrashResponse (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/logger.js:38:9)
at process.<anonymous> (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:233:22)
at process.emit (events.js:400:28)
at process.emit (domain.js:470:12)
at processPromiseRejections (internal/process/promises.js:245:33)
at processTicksAndRejections (internal/process/task_queues.js:96:32) 下面是我的函数:
exports.scheduledFunction = functions.pubsub
.schedule("every 5 minutes")
.onRun((context) => {
console.log("This will be run every 5 minutes!");
const tsToMillis = admin.firestore.Timestamp.now().toMillis();
// const compareDate = new Date(tsToMillis - 24 * 60 * 60 * 1000);
const compareDate = new Date(tsToMillis - 5 * 60 * 1000);
admin
.firestore()
.collection("properties").where("status", "==", "Reserved")
.where("reservationDate", "<", compareDate)
.where("paymentIsDone", "==", false)
.get()
.then((querySnapshot) => {
querySnapshot.forEach((doc) => {
admin.firestore().collection("properties").doc(doc.id).update({
agent: "",
reservedBy: "",
reservedByPhoneNumber: "",
reservationDate: null,
status: "Remaining",
});
console.log("canceling reservations");
});
});
return null;
});我想取消预订后24小时内(用于测试5分钟)内未完成付款的物业的预订。
这就是我预留房产的方式:
exports.reserveApt = functions.https.onCall((data, context) => {
if (!context.auth) {
return {
result: "failed",
msg: "you are not authenticated",
};
}
const doc = admin.firestore().collection("properties").doc(data.aptId);
// get apt
return doc.get().then((apt) => {
apt = apt.data();
// check apt is not already reserved or sold
// console.log(apt);
if (apt.status !== "Remaining") {
return {
result: "failed",
msg: "Appartment is already reserved or sold",
};
}
// reserve apt with username and phone and changes status to reserved
return doc
.update({
agent: data.agent,
reservedBy: data.reserveeName,
reservedByPhoneNumber: data.reserveePhone,
reservationDate: admin.database.ServerValue.TIMESTAMP,
status: "Reserved",
paymentIsDone: false,
})
.then(() => {
console.log("apt reserved");
return {result: "success"};
});
});
});是时间戳有问题还是怎么的?我不明白。
发布于 2021-10-26 14:26:52
您正在使用.where()在相等运算符(==或array-contains)和不等运算符(<、<=、>和!=)之间执行复合查询,其中is invalid in Firebase。
admin
.firestore()
.collection("properties")
.where("status", "==", "Reserved") // First query, using equality comparator
.where("reservationDate", "<", compareDate) // ERROR! You're using inequality operator '<' after '=='要执行这样的操作,您需要执行create an index;,这可以通过following the error message完成(检查您的Cloud Functions,单击您的函数,单击LOGS选项卡并搜索错误)。
https://stackoverflow.com/questions/69627572
复制相似问题