('{openid}'不支持查询指令,需要后端获取)? 没太懂 云开发 数据库 安全规则详解的帖子

小程序 文章 2021-03-05 20:01 484 0 全屏看文

AI助手支持GPT4.0

('{openid}'不支持查询指令,需要后端获取)? 没太懂 云开发 数据库 安全规则详解的帖子('{openid}' does not support query commands and needs to be obtained from the backend)? I don’t know much about cloud development, databases, and security rules in detail.

('{openid}'不支持查询指令,需要后端获取)? 没太懂 云开发 数据库 安全规则详解的帖子

https://developers.weixin.qq.com/community/business/doc/000eaa8ba2c9482d16ca7dab456c0d

云开发安全规则讲解 官方 的帖子 在微信学院里面

引用原文

2、把权限指定给某些人

上面的这个角色指定是一对一、或多对一的指定,也可以是一对多的指定,可以使用in!(xx in [])运算符。比如下面是可以给一个记录指定多个角色(学生创建的记录,多个老师有权读写):

//文档的结构{  _id:"handwork20201020",  _openid:"学生的openid", //学生为记录的创建者,  teacher:["老师1的openid","老师2的openid","老师3的openid"]}//安全规则{  "read": "auth.openid in doc.teacher || doc._openid == auth.openid",  "write": "auth.openid in doc.teacher || doc._openid == auth.openid",}

这里要再强调的是前端(小程序端)的 where 条件必须是安全规则权限的子集,比如我们在小程序端针对老师进行如下查询('{openid}'不支持查询指令,需要后端获取)

db.collection("集合id")  .where({    _openid: "{openid}",    teacher: _.elemMatch(_.eq("老师的openid")),  })  .get()  .then((res) => {    console.log(res);  });
前面我们实现了将记录的权限指定给某个人或某几个人,那如何将记录的权限指定给某类人呢?比如打车软件为了数据的安全性会有司机、乘客、管理员、开发人员、运维人员、市场人员等,这都需要我们在数据库里新建一个字段来存储用户的类型,比如 {role:3} ,用 1、2、3、4 等数字来标明,或者用 {isManager:true} boolean 类型来标明,这个新增的字段可以就在查询的集合文档里 doc.role ,或者是一个单独的集合(也就是存储权限的集合和要查询的集合是分离的,这需要使用 get 函数跨集合查询),后面会有具体介绍。


不太清楚这个小程序端,针对老师进行如下查询

db.collection("集合id")  .where({    _openid: "{openid}",    teacher: _.elemMatch(_.eq("老师的openid")),  })  .get()  .then((res) => {    console.log(res);  });

我试了下,get到了寂寞

这个where 条件似乎不是安全规则权限的子集,然后被拒绝了。

针对老师端,这个"{openid}"肯定是老师的了,那么他就一定找不到想要的学生记录,是写错了还是我理解做了。

 .where({    teacher: _.elemMatch(_.eq("{openid}")),  })

也会被没有权限拒绝


菜鸟不太理解这里,求大神指点迷津。

https://developers.weixin.qq.com/community/business/doc/000eaa8ba2c9482d16ca7dab456c0d Cloud development security rules explain the official post in wechat college quoted the original 2. Assign permissions to some people. The role above can be specified as one-to-one, or many to one, or one to many. You can use the in or! (XX in []) operator. For example, you can assign multiple roles to a record (records created by students, and multiple teachers have the right to read and write): / / the structure of the document {_ id:"handwork20201020", _ Openid: "student's openid", / / student is the creator of the record, teacher: ["teacher 1's openid", "teacher 2's openid", "teacher 3's openid"]} / / security rule {"read":“ auth.openid in doc.teacher || doc._ openid == auth.openid ", "write": " auth.openid in doc.teacher || doc._ openid == auth.openid ",} it should be emphasized here that the where condition of the front-end (applet side) must be a subset of the security rule permissions. For example, we make the following query for the teacher on the applet side ('{openid}' does not support the query instruction and needs to be obtained by the back-end) db.collection ("set ID"). Where ({set ID ")_ openid: "{openid}", teacher: _ .elemMatch(_ . EQ ("teacher's openid"),}). Get (). Then ((RES) = >{ console.log (RES);}); previously, we have assigned the record permission to a certain person or several persons. How can we assign the record permission to a certain kind of person? For example, taxi software has drivers, passengers, administrators, developers, operation and maintenance personnel, marketing personnel and so on for data security, which requires us to create a new field in the database to store the type of user, such as{ role:3 }1, 2, 3, 4, etc., or{ isManager:true }boolean Type to indicate that the new field can be in the collection document of the query doc.role , or a separate set (that is, the set of storing permissions and the set to be queried are separated, which needs to use the get function to query across sets), which will be described in detail later. Not clear about this small program side, for the teacher to carry out the following query db.collection ("set ID"). Where ({set ID ")_ openid: "{openid}", teacher: _ .elemMatch(_ . EQ ("teacher's openid"),}). Get (). Then ((RES) = >{ console.log (RES);}); I tried, and got the lonely where condition, which seems not to be a subset of the security rule permissions, and was rejected. For the teacher side, this "{openid}" must be the teacher's, so he must not find the student record he wants. Is it a mistake or I understand and do it. .where({ teacher: _ .elemMatch(_ . EQ ("{openid}"),}) will also be refused without permission. Rookies don't quite understand here and ask the great God for advice.

回答:

跨商通:
"{openid}"


这种文字应该理解为:这里填用户的openid

Mr.Zhao:

@奇[旺柴]:学生端的话,这个访问权限是没问题,但是根据
这个安全规则的本意 是  把权限指定给某些人

这里是要把这个集合的记录给老师访问,那么我老师端的where条件该怎么写呢?


 .where({
    teacher: db.comand. elemMatch(  db.comand.eq(“{openid}”)),
  })


我试过这种写法,会被拒绝数据库以没有权限拒绝
@奇[旺柴]:
或者说,我不知道这个 auth.openid in doc.teacher

的where条件子集怎么写,也没找到相关示例

-EOF-

AI助手支持GPT4.0


国内超级便宜服务器

摸鱼人热门新闻聚合

钻级赞助商 我要加入

开发者在线工具

第三方支付技术请加QQ群

相关文章
我有小程序账户我想绑定公众号并且获取UnionID 有什么要求吗?
打开小程序提示“需要微信授权以获取小程序数据”,这个要怎么解决?
【急】微信服务号下午4点开始,被动消息回复异常?
5年多!公众号流量主没有结算,现在有20多万的收益,请问如何结算?
小程序开发工具为什么有的时候看不到WXML?已是最新版本
随便看看
教育科技公司申请微信支付被拒绝? 3923
微信公众号免300认证教程 5027
小程序已经上线,作为管理员无法在小程序数据助手查看数据? 4249
小程序广告组件通过审核,但是小程序内没有显示广告? 4324
企业微信通讯录账号被管理员误/恶意删除,怎么办? 8122
问题? 7448
如何快速搭建抽奖助手小程序(无需代码知识) 5125
许涛 大哥在吗, 要解冻小程序的时候提示信息主体不一致, 能帮忙看下吗? 6083
小程序搜一搜全称搜索不显示 麻烦解决一下!谢谢 5693
我的小程序广告收款主体是个体工商户,每个月邮寄两次发票很是麻烦,我年底的时候打包邮寄一次可以么? 5278