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

Firestore调用DocumentReference.update()更新布尔字段报错求助

解决Firestore布尔字段更新失败问题

问题原因

  1. update()方法参数错误:Firestore的DocumentReference.update()必须接收键值对对象,用来指定要更新的字段名和对应值,你直接传入true不符合API要求。
  2. 文档路径拼接错误:错误提示里的lunch/isBagundefined说明this.userID未正确赋值,导致路径拼接后出现undefined,无法定位到目标文档。

修正后的代码

先确保this.userID已正确获取到用户ID值,再使用以下代码:

this.firestore.doc(`lunch/${this.userID}`).update({ isBag: true });

说明

  • 用模板字符串${this.userID}拼接路径,确保文档路径为lunch/[你的用户ID],匹配截图里的集合与文档结构。
  • update({ isBag: true })明确指定要将isBag字段更新为true,符合Firestore的参数规范。

内容的提问来源于stack exchange,提问作者Vinícius Kock

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 10:35:33