TypeError:无法读取未定义的属性(读取“arrayRemove”)

编程入门 行业动态 更新时间:2024-10-07 03:27:08

TypeError:无法读取未定义的<a href=https://www.elefans.com/category/jswz/34/1771415.html style=属性(读取“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”)

本文发布于:2024-05-30 16:00:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770669.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   未定义   TypeError   arrayRemove

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!