调用云函数,在云函数中执行同样的代码操作成功;但是直接在前端调用 clientDB API
就报错。直接贴上代码:
前端调用clientDB API:
const db = uniCloud.database()
db.collection('community').add({
name: "test",
category_id: "6037330d5dc5370001f4db74"
})
schema如下:
{
"bsonType": "object",
"required": ["name", "category_id"],
"permission": {
"read": true,
"create": true,
"update": "auth.uid in doc.managers || auth.uid==doc.creator_id",
"delete": "auth.uid==doc.creator_id"
},
"properties": {
"_id": {
"description": "存储文档 ID(文章 ID),系统自动生成"
},
"name": {
"bsonType": "string",
"description": "鱼塘名称",
"title": "名称",
"trim": "both"
},
"category_id": {
"bsonType": "string",
"description": "类型id,参照 `community-category` 表",
"foreignKey": "community-category._id"
},
"status": {
"bsonType": "int",
"description": "状态:0 正常 1 禁用 2 审核中 3 审核拒绝",
"title": "状态",
"defaultValue": 0,
"enum": [{
"text": "正常",
"value": 0
}, {
"text": "禁用",
"value": 1
}, {
"text": "审核中",
"value": 2
}, {
"text": "审核拒绝",
"value": 3
}]
},
"avatar": {
"bsonType": "string",
"title": "头像地址",
"description": "头像地址",
"format": "url",
"trim": "both"
},
"comment": {
"bsonType": "string",
"description": "鱼塘描述",
"title": "描述",
"trim": "both"
},
"managers": {
"bsonType": "array",
"description": "管理员id, 参照 `uni-id-users` 表",
"permission": {
"update": "auth.uid in doc.managers || auth.uid==doc.creator_id"
}
},
"keywords": {
"bsonType": "string",
"description": "用于搜索的关键词",
"trim": "both"
},
"creator_id": {
"bsonType": "string",
"description": "创建者id, 参照 `uni-id-users` 表",
"foreignKey": "uni-id-users._id",
"forceDefaultValue": {
"$env": "uid"
}
},
"create_date": {
"bsonType": "timestamp",
"description": "创建时间",
"forceDefaultValue": {
"$env": "now"
}
}
}
}
订:
在微信小程序后台配置域名白名单后,报错信息变更为了 未能获取当前用户信息:30205 | 当前用户为匿名身份
1 个回复
5***@qq.com (作者)
找到原因了,把schame中的
creator_id
字段配置的强制默认字段删除就可以了。但是没有从根本上解决问题,求问怎么把当前用户变为正式用户??