TXAMAXT
TXAMAXT
  • 发布:2025-03-07 17:13
  • 更新:2025-03-26 22:22
  • 阅读:185

clientDB,在前端访问数据库报权限错误,但我的schema的权限全给了。

分类:uni-app

这是表结构
{
"schema": {
"bsonType": "object",
"required": ["name"],
"permission": {
"read": true,
"create": true,
"update": true,
"delete": true
},
"properties": {
"_id": {
"description": "分类ID,系统自动生成",
"permission": {
"read": true,
"create": true,
"update": true,
"delete": true
}
},
"name": {
"bsonType": "string",
"description": "分类名称",
"title": "分类名称",
"trim": "both",
"permission": {
"read": true,
"create": true,
"update": true,
"delete": true
}
},
"description": {
"bsonType": "string",
"description": "分类描述",
"maxLength": 500,
"permission": {
"read": true,
"create": true,
"update": true,
"delete": true
}
}
}
},
"index": [
{
"IndexName": "name",
"MgoKeySchema": {
"MgoIndexKeys": [{
"Name": "name",
"Direction": "1"
}],
"MgoIsUnique": true
}
}
]
}
前端代码
<script setup>
import {mapState,mapGetters,mapMutations,mapActions} from "vuex";
const controlCategories = uniCloud.importObject('controlCategories');
const db = uniCloud.databaseForJQL();
export default {
//mixins: [], // ② 引入 mixin调用公共模块
//props: {}, ③ 定义 props(接收外部参数)组件使用
data() { // ④ 定义响应式数据(变量)
return {
list:[{
name: '最近浏览',
}, {
name: '全部',
}]
};
},
computed: { // ⑤ 计算属性,基于 data 计算

},
watch: { // ⑥ 监听数据变化

},
methods: { // ⑦ 定义方法
async fetchCategories() {
db.collection('categories').where('_id == "67c8820a3d029caca1742580"').get().then(res => {
console.log(res);
}).catch(err => {
console.error(err)
});
// try {
// const {data} = await controlCategories.getCategories();
// console.log(data);
// } catch (error) {
// console.error('调用云对象失败:', error);
// uni.showToast({
// title: '调用云对象失败',
// icon: 'none'
// });
// }
}
},
onLoad() { // ⑧ 生命周期 - 页面加载
console.log("页面加载");

},
onShow() { // ⑨ 生命周期 - 页面显示
console.log("页面显示");
this.fetchCategories();
},
onReady() { // ⑩ 生命周期 - 页面渲染完成
console.log("页面渲染完成");
},
onUnload() { // ⑪ 生命周期 - 页面卸载
console.log("页面卸载");
}
};
</script>

2025-03-07 17:13 负责人:无 分享
已邀请:
TXAMAXT

TXAMAXT (作者)

已解决,如果想使用clientDB,在前端访问数据库,表结构中不能添加"schema"字段

要回复问题请先登录注册