1***@qq.com
1***@qq.com
  • 发布:2023-07-28 03:09
  • 更新:2024-07-16 23:40
  • 阅读:234

云数据库require字段配置的必填字段失效

分类:uniCloud

{
"bsonType": "object",
"required": ["address","price","project_name"],
"permission": {
"read": true,
"create": true,
"update": true,
"delete": true
},
"properties": {
"_id": {
"description": "ID,系统自动生成"
},
"img": {
"bsonType": "string",
"description": "列表图片"
},
"project_name": {
"title": "楼盘项目名称",
"bsonType": "string",
"description": "楼盘项目名称",
"trim": "both"
},
"address": {
"title": "楼盘项目地址",
"bsonType": "string",
"description": "楼盘项目地址"
},
"price": {
"title": "均价",
"bsonType": "string",
"description": "均价"
},
"house_type": {
"bsonType": "string",
"description": "楼盘户型"
},
"area": {
"bsonType": "string",
"description": "面积"
},
"create_date": {
"bsonType": "timestamp",
"title": "创建时间",
"forceDefaultValue": {
"$env": "now"
}
}
}
}

上面是schema


下面是我的请求

const data = [{project_name:'邱军强测试6666666666'}];

fetch('https://fc-mp-c3fc9061xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/importHouseList', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(response => response.json())
.then(data => {
console.log(data);
})
.catch(error => {
console.error('Error:', error);
});

云函数代码:
async importHouseList(param1) {

    const httpInfo = this.getHttpInfo()  
    try {  
        //拿到db对象  
        const db = uniCloud.database();  
        //连接数据库  
        const collection = db.collection('house-list');  
        //isBase64Encoded的话 直接上  
        let params = httpInfo.isBase64Encoded ? httpInfo.body : JSON.parse(httpInfo.body)  
        let res = await collection.add(params)  
        return {  
            codeCode:200,  
            res  
        }  
    } catch (e) {  
        //TODO handle the exception  
        return {  
            e,  
            errMsg: "失败了",  
            httpInfo: httpInfo  
        }  
    }  
}  

返回结果:
{
"codeCode": 200,
"res": {
"inserted": 1,
"result": {
"0": "64c2bd5e466d416d30951f8d"
},
"ids": [
"64c2bd5e466d416d30951f8d"
]
}
}

啊?????必填校验呢,怎么数据库就插入成功了

2023-07-28 03:09 负责人:无 分享
已邀请:
喜欢技术的前端

喜欢技术的前端 - QQ---445849201

你好,可以在后台看一下,插入的这条数据"address","price","project_name" 字段有值吗

  • 1***@qq.com (作者)

    看了一下, 没有值

    2023-07-31 08:15

3***@qq.com

3***@qq.com - 刚刚开始写小程序

hello,想问问解决了吗

要回复问题请先登录注册