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

小程序 文章 2021-03-05 20:01 472 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