属性(读取“arrayRemove”)"/>
TypeError:无法读取未定义的属性(读取“arrayRemove”)
我在 firebase 模拟器中有一个云函数,我正在尝试更新一个数组。但是,当函数运行时,出现以下错误:
TypeError: Cannot read properties of undefined (reading 'arrayRemove')
。我不确定出了什么问题。我的节点版本是 16.
这是我的功能代码:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const db = admin.firestore();
const storage = admin.storage();
exportspleteEventRegistration = functions.firestore
.document("<path>")
.onCreate(async (snap, context) => {
// <ommitted>
try {
await db.runTransaction(async (transaction) => {
// <omitted>
const fieldValue = admin.firestore.FieldValue;
transaction.update(committeeRef, {"countries": fieldValue.arrayRemove({
"name": chosenCountry,
"taken": false,
})});
});
} catch (error) {
console.log("Error registering: ", error);
throw new functions.https.HttpsError("internal", "Error registering");
}
});
回答如下:
fieldValue
似乎没有定义/声明。您需要声明如下:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const fieldValue = require('firebase-admin').firestore.FieldValue;
更多推荐
TypeError:无法读取未定义的属性(读取“arrayRemove”)
发布评论