- 数据库中有两个集合:
adminList
{ "_id":str,
"isAdmin":boolean,
"managerOfShop":[],
"_openid":{openid},
"admin":{openid}
}
draftUserInfo
{"_id":str,"
_openid":{openid},
"cardNo":str,
"isNew":boolean,
"nickName":str,
"phoneNo":str,
"shops":[]
}
2.想实现对draftUserInfo的访问规则为:只有集合admin里的管理员(根据isAdmin或者admin字段判断)可读
3.对draftUserInfo设了下面两个安全规则都不生效,读不出数据
{
"read": "auth.openid==get('database.adminList.${doc._id}').admin",
"write": "doc._openid == auth.openid"
}
设下面规则时,还必须加上"==true",否则报错
{
"read": "get('database.adminList.${auth.openid}').isAdmin==true",
"write": "doc._openid == auth.openid"
}
折腾了一天也不知道怎么回事,请各位指点迷津,多谢了
代码片段
db.collection('draftUserInfo').where({ _openid:openid,isNew:true }).get({ success: function(res) { var ui=res.data that.setData({ userInfo:ui })
@Mr.Zhao 多谢解答,但我改成双引号,己直接报错了:
"read": "get("database.adminList.${auth.openid}").isAdmin==true",
我是初学者,很多语法都不懂,还请详细指导一下,谢谢
js中的get语句如下:
db.collection('draftUserInfo').where({
isNew:true,
}).get({
success: function(res)
${auth.openid} 这个是字符串模板语法,应该用反引号,而不是单引号