复制代码db.collection('opendb-news-comments').add({
article_id:this.id,
user_id:db.env.uid,
comment_content:this.commentContent,
like_count:0,
comment_type:0,
reply_user_id:'',
reply_comment_id:''
}).then((res) => {
//评论成功
this.$refs.uToast.show({
title: '评论成功',
position: 'bottom'
})
//TODO
}).catch((err) => {
//评论失败
console.log(err)
}).finally(() => {
})
opendb-news-comments.schem.json
复制代码{
"bsonType": "object",
"required": ["article_id", "user_id", "comment_content", "like_count", "comment_type", "reply_user_id",
"reply_comment_id"
],
"permission": {
"read": true,
"create": "auth.uid != null && get(`database.opendb-news-articles.${doc.article_id}`).comment_status == 1",
"update": "doc.uid == auth.uid",
"delete": "doc.uid == auth.uid"
},
"properties": {
"_id": {
"description": "存储文档 ID(文章 ID),系统自动生成"
},
"article_id": {
"bsonType": "string",
"description": "文章ID,opendb-news-posts 表中的`_id`字段",
"foreignKey": "opendb-news-articles._id"
},
"user_id": {
"bsonType": "string",
"description": "评论者ID,参考`uni-id-users` 表",
"forceDefaultValue": {
"$env": "uid"
},
"foreignKey": "uni-id-users._id"
},
"comment_content": {
"bsonType": "string",
"description": "评论内容",
"title": "评论内容",
"trim": "right"
},
"like_count": {
"bsonType": "int",
"description": "评论喜欢数、点赞数"
},
"comment_type": {
"bsonType": "int",
"description": "回复类型: 0 针对文章的回复 1 针对评论的回复"
},
"reply_user_id": {
"bsonType": "string",
"description": "被回复的评论用户ID,comment_type为1时有效",
"foreignKey": "uni-id-users._id"
},
"reply_comment_id": {
"bsonType": "string",
"description": "被回复的评论ID,comment_type为1时有效",
"foreignKey": "opendb-news-comments._id"
},
"comment_date": {
"bsonType": "timestamp",
"description": "评论发表时间",
"forceDefaultValue": {
"$env": "now"
}
},
"comment_ip": {
"bsonType": "string",
"description": "评论发表时 IP 地址",
"forceDefaultValue": {
"$env": "clientIP"
}
}
}
}
当schem.permission.create写成"auth.uid != null && get(database.opendb-news-articles.${doc.article_id}
).comment_status == 1"报这样的报错,不知你们有没有遇到,是我哪里写错了吗?
复制代码12:03:28.030 Error: opendb-news-comments['.create']:get方法内参数值必须唯一位置:24-73 at pages/article/detail/index.vue:367
天涯孤客 (作者)
刚刚看到文档里这句话你就回我了,“doc是有客户端条件里面提取的变量,因此create权限内不可使用doc变量,建议使用forceDefaultValue或自定义校验函数实现插入数据的校验。”,但是这表我是在后台使用OpenDB表模板创建的,里面就是这么写,误导人呀,害我找了半天原因,以为哪里写错了
2021-02-25 15:39
DCloud_uniCloud_WYQ
回复 天涯孤客: 了解,我们改一下
2021-02-25 16:54
搬码超6
回复 DCloud_uniCloud_WYQ: 怎么改,我也遇到了
2021-09-02 17:43
2***@qq.com
回复 DCloud_uniCloud_WYQ: 现在还没有改哦,评论表模板中create权限还是用了doc
2023-10-19 22:21