一、前端操作数据库(持续更新)
增
const db = uniCloud.database();
//db.collection("你的云数据库表名")
db.collection("lt_lunbo")
.add({
url :'',
go_url : '',
name : "测试0",
})
.then((res) => {
uni.showToast({
title: '新增成功'
})
})
.catch((err) => {
uni.showToast({
title: '新增失败'
})
})
删
db.collection("table1").where("a>2").remove()
改
const db = uniCloud.database();
let collection = db.collection("table1")
let res = await collection.where({_id:'doc-id'})
.update({
name: "Hey"
})
查
const db = uniCloud.database()
let res = db.collection('lt_lunbo').where().limit(5).orderBy('time',"desc").get()
// console.log('查询的数据',res)
//limit查几条数据
//orderBy 根据什么排序 desc倒叙 取出最新的数据
//where 查询条件 不用可以删除
res.then( r => {
console.log(r.result.data)
his.imgData = r.result.data
})
二、云函数基础操作
//前端
uniCloud.callFunction({
name: '你自己的云函数名字',
data: {
value: "1810"
},
success: (res) => {
console.log(res)
}
})
//云函数端'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
//event为客户端上传的参数
console.log('event : ', event)
//返回数据给客户端
return event
};
where中or
let text = '模糊查询的数据'
.where(
dbCmd.or({
dd_name : new RegExp(`${text}`),
}, {
dd_cc : new RegExp(`${text}`),
}, {
dd_ks : new RegExp(`${text}`),
}, {
dd_zdy : new RegExp(`${text}`),
}, {
dd_now : new RegExp(`${text}`),
})
)