You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Firebase云函数模块化迁移:FieldValue语法使用疑问

Firebase模块化SDK中FieldValue的调用方式

你不需要再通过admin命名空间访问FieldValue,Firebase模块化SDK提供了更简洁的导入和调用方式:

Admin SDK模块化版本(云函数场景适用)

直接从firebase-admin/firestore导入FieldValue,调用逻辑和原代码保持一致:

import { FieldValue } from "firebase-admin/firestore";

await firestoreDb.doc(`/${projectsPath}/${projectKey}`).update({
  roUids: FieldValue.arrayRemove(uidOfUserToDelete),
  rwUids: FieldValue.arrayRemove(uidOfUserToDelete),
});

客户端模块化SDK(若涉及客户端代码参考)

如果是客户端开发场景,可直接导入对应的操作函数,无需通过FieldValue层级调用:

import { arrayRemove } from "firebase/firestore";

await firestoreDb.doc(`/${projectsPath}/${projectKey}`).update({
  roUids: arrayRemove(uidOfUserToDelete),
  rwUids: arrayRemove(uidOfUserToDelete),
});

云函数场景下优先使用Admin SDK的模块化导入方式,能更好地和其他Admin模块化API保持语法统一。

内容的提问来源于stack exchange,提问作者Jørgen Rasmussen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 13:17:02