uniCloud调用云函数
uniCloud.callFunction({
name:"云函数名称",
data:{"数据"},
success(){
//成功
},
fail(){
//失败
}
})
unCloud调用云数据库
const db = uniCloud.database();
exports.main = async (event, context) => {
//获取集合/数据表
const collection = db.collection('user');
//添加数据 await代表同步运行
const res = await collection.add([
{
name:"库兹马",
age:"26",
No:"0",
team:"洛杉矶湖人"
},
{
name:"戴维斯",
age:"28",
No:"3",
team:"洛杉矶湖人"
}
])
//删除数据
const res = await collection.doc('60a6099cfa23870001718106').remove()
// 更新数据 update或者set set如果没找到id 则会新增一条数据
const res = await collection.doc('60a609ad5b70b50001a6d897').update(
{
name:"科比",
age:"20",
No:"24",
team:"洛杉矶湖人"
}
)
//查询数据——根据id查找 doc只能应用于id
const res = await collection.doc('60a609ad5b70b50001a6d897').get()
console.log(JSON.stringify(res))
//查询数据——根据条件查找 使用where
const res = await collection.where({
team:"洛杉矶湖人"
}).get()
console.log(JSON.stringify(res))
//返回数据给客户端
return {
code:200,
msg:'查询成功',
data:res.data
}
};