收藏
回答

数据权限问题

框架类型 问题类型 终端类型 AppID 环境ID 基础库版本
小程序 Bug 微信安卓客户端 wxd9bf99b34cbc9425 listen-2gskorawde4c93ea 2.14.1

https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/database/security-rules.html

{

"read": "auth.openid == 'oEQLf4rd8w2C85Ly3B8FxXXyz8RA' || doc._openid == auth.openid",

"create": true,

"update": "auth.openid == 'oEQLf4rd8w2C85Ly3B8FxXXyz8RA' || doc._openid == auth.openid",

"delete": "auth.openid == 'oEQLf4rd8w2C85Ly3B8FxXXyz8RA' || doc._openid == auth.openid"

}

指定openid = 'oEQLf4rd8w2C85Ly3B8FxXXyz8RA'的用户或者记录创建者可查看修改删除, 此时只有指定的用户可以查看信息, 创建者查看报错

Error: errCode: -502003 database permission denied | errMsg: Permission denied

    at new s (VM1665 WAService.js:2)

    at Function.success (VM1665 WAService.js:2)

    at C (VM1665 WAService.js:2)

    at Object.success (VM1665 WAService.js:2)

    at Q (VM1665 WAService.js:2)

    at d (VM1665 WAService.js:2)

    at VM1665 WAService.js:2

    at A.<anonymous> (VM1663 asdebug.js:1)

    at C (VM1665 WAService.js:2)

    at VM1665 WAService.js:2

回答关注问题邀请回答
收藏

2 个回答

  • 刘栋
    刘栋
    2020-12-14

    是因为你没有在查询语句中填写 openid,

    db.collection('xxx').where({_openid: 'xxxxxxxxxx'}).get()
    

    比如权限是 {"read": "doc.key == '12321'"} ,就要求在查询语句里有key:'12321 ' ,即where({key:'12321'}),否则拒绝访问。

    文档中有说明:

    https://developers.weixin.qq.com/miniprogram/dev/wxcloud/guide/database/security-rules.html#%E7%AE%80%E4%BB%8B



    2020-12-14
    有用 1
    回复 2
    • Mr.L
      Mr.L
      2022-03-04
      但是如果增加了_openid: '{openid}', 似乎上面指定的用户是无法查看其他人创建的了?
      2022-03-04
      回复
    • 蓝星空
      蓝星空
      2022-11-19
      果然是加上 _openid 就可以了。
      2022-11-19
      回复
  • 疯狂的小辣椒
    疯狂的小辣椒
    2020-12-14

    经核实,请求的openid 确实不是你写的这个openid,还请自查。

    2020-12-14
    有用
    回复
登录 后发表内容
问题标签