森屿阁
森屿阁
  • 发布:2025-06-06 16:47
  • 更新:2025-06-09 11:38
  • 阅读:108

【报Bug】defaultValue和forceDefaultValue设置无效

分类:uniCloud

产品分类: uniCloud/App

操作步骤:

{
"bsonType": "object",
"required": [
"name"
],
"permission": {
"read": true,
"create": true,
"update": true,
"delete": true
},
"properties": {
"_id": {
"description": "存储文档 ID(文章 ID),系统自动生成"
},
"parent_id": {
"bsonType": "string",
"description": "父ID,用于多级分类"
},
"name": {
"bsonType": "string",
"description": "类别名称",
"title": "类别名称",
"trim": "both"
},
"icon": {
"bsonType": "string",
"description": "类别图标/图片地址",
"title": "图标地址",
"trim": "both"
},
"sort": {
"bsonType": "int",
"description": "类别排序,越大越靠后",
"title": "排序"
},
"description": {
"bsonType": "string",
"description": "类别描述",
"title": "类别描述",
"trim": "both"
},
"is_hot_show": {
"bsonType": "bool",
"title": "加入热门显示",
"description": "是否热门显示"
},
"is_index_show": {
"bsonType": "bool",
"title": "首页显示",
"description": "是否首页显示"
},
"create_date": {
"bsonType": "timestamp",
"description": "创建时间",
"forceDefaultValue": {
"$env": "now"
}
},
"userUid":{
"bsonType": "string",
"forceDefaultValue": {
"$env": "uid"
}
}
},
"version": "0.0.1"
}

预期结果:

数据库每新增数据时create_date的forceDefaultValue设置成功

实际结果:

数据库每新增数据时create_date的forceDefaultValue设置不成功

bug描述:

schema设置forceDefaultValue和defaultValue无效,当提交数据不传参数,设置的默认值无效

2025-06-06 16:47 负责人:无 分享
已邀请:

最佳回复

DCloud_uniCloud_VK

DCloud_uniCloud_VK

先说结论:此非bug,schema本身仅对JQL语句生效。

原因:JQL是unICloud官方在传统db的基础上封装的,并不是数据库本身的功能,只有通过代码 const dbJQL = uniCloud.databaseForJQL 获得的 dbJQL 对象去操作数据库才受到 schema 的影响。

要回复问题请先登录注册