收藏
回答

使用db.collection('xxx').update({...})更新一条数据的字段值失败?

代码如下

const db = wx.cloud.database()
      db.collection('articles').doc(that.data.collectID).update({
        data: {
          focustrue
        },
        successfunction(res{
          console.log('res:', res)
          wx.hideLoading()
          that.succMsgTip()
        },
        failfunction(err{
          // console.log('err:', err)
          wx.hideLoading()
          that.errMsgTip()
        }
      })


首先我使用get()是可以正确获取到对应ID的内容

db.collection('articles').doc(that.data.collectID).get().then(res => { console.log('get res:', res)})


此时查看 focus 再数据库中的类型为boolean 当前值为 false

然后我打印返回也是OK的

errMsg: "document.update:ok"
stats: {updated0}


提示成功后 刷新数据库查看并没有修改focus的值为true

所以这是哪里不对吗 ?

上面给出了update: 0 但是没具体提示了 , 一头雾水

最后一次编辑于  06-19
回答关注问题邀请回答
收藏

2 个回答

  • 莫问前尘
    莫问前尘
    06-19

    终于知道为什么了, 因为集合设置权限问题 , 使用自定义权限 读写都放开就OK了。。。

    06-19
    有用 1
    回复
  • 智能回答 智能回答 本次回答由AI生成
    06-19
    有用 1
登录 后发表内容