请问云函数中我怎么通过openid来修改自己的数据呢?总是不成功

小游戏 企业微信 微信支付 小程序 文章 2020-07-30 21:01 926 0 全屏看文

AI助手支持GPT4.0

请问云函数中我怎么通过openid来修改自己的数据呢?总是不成功
框架类型 问题类型 操作系统 工具版本
小游戏 需求 Windows v1.02

我通过云函数创建了一条数据,自动添加了_openid字段,我发现我如果doc的是_id字段,是可以通过update修改数据的,但是我doc了_openid字段,修改完数据不成功,我在社区里看有人说是权限问题,可是我该怎么做才能让集合认为我有权限修改呢,毕竟_id不是唯一的,用户的openid才是吧

return db.collection('Around1').doc(wxContext.OPENID).update({data:{_openid:wxContext.OPENID, score:10}});

其中Around1是我集合的名字,这样不能修改数据吗?求大神指点

Framework type problem type operating system tools version game requirements windows v1.02 I created a piece of data through cloud function and added it automatically_ Openid field, I found that if the doc is_ The ID field can be modified through update, but I do_ For the openid field, modifying the data failed. I saw that some people in the community said that it was a permission problem. But what should I do to make the collection think that I have permission to modify it? After all_ The ID is not unique. The user's openid is the return db.collection ('Around1').doc( wxContext.OPENID ).update({data:{_ openid:wxContext.OPENID , score:10 }}); where around1 is the name of my collection. Can't you modify the data? Ask God for advice

回答:

o0o有脾气的酸奶:

_id是唯一的

doc只能是_id的值

你想使用_openid进行更新就是用where,如:

return db.collection('Around1').where({ _openid: wxContext.OPENID }).update({data:{score:10}});


一定要使用doc(_openid的值)的话,除非是你在添加数据的时候_id的是就是_openid的值,如

db.collection('Around1').add({  data:{    _id: wxContext.OPENID,    xxx: '' //其他字段    ...  }});


这样你才可以使用

db.collection('Around1').doc(wxContext.OPENID).update({data:{score:10}});


值得注意的是,_id字段是主键,不能重复

若认为该回答有用,给回答者点个[ 有用 ],让答案帮助更多的人

李伟:感谢解答

-EOF-

AI助手支持GPT4.0