{
"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"
]
}
}
啊?????必填校验呢,怎么数据库就插入成功了
1***@qq.com (作者)
看了一下, 没有值
2023-07-31 08:15