我正在 firebase 模拟器中测试云功能,并在尝试增加云 firestore 中的字段时收到错误。请检查下面我的代码和错误消息。谢谢你的帮助!
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
admin.initializeApp();
const db = admin.firestore();
export const newUserIncrementStat = functions.firestore.document("users/{uid}").onCreate((snap, context) => {
const docRef = db.doc("stats/users");
try {
return docRef.set({
totalUsers: admin.firestore.FieldValue.increment(1),
}, {merge: true});
} catch (e) {
console.log("Something is wrong: ", e);
return Promise.reject(e);
}
});
Run Code Online (Sandbox Code Playgroud)
Firebase 日志中的错误消息:
类型错误:无法读取未定义的属性(读取“增量”)
依赖关系
firebase 管理员:“^11.0.0”
firebase 函数:“^3.22.0”
火力基地:11.3.0
firebase typescript firebase-tools google-cloud-functions google-cloud-firestore