微信公众平台–小程序操作云数据库–插入
(1)通过控制台:创建集合web
(2)初始化默认云数据库
const db = wx.cloud.database();
(3)向集合中添加新记录
db.collection("集合名称").add(
{
data:{name:"文华",age:60},
success:function(res){},
fail:function(){}
}
)
微信公众平台–小程序操作云数据库–更新
db.collection("集合名称").doc("当前记录id").update({
data:{
属性名:值
}
}).then(res=>{
console.log(res)
}).catch(err=>{
console.log(err)
}
)
微信公众平台–小程序操作云数据库–删除
db.collection("集合名称").doc(记录id).remove().then(res=>{}).catch(err=>{})
#注意事项:通过小程序一次只能删除一条数据
微信公众平台–小程序操作云数据库–查询
(1)查询所有数据
db.collection("集合名称").get().then(res=>{}).catch(err=>{})
(2)查询指定数据
db.collection("集合名称").where({name:"jerry"}).get().then(res=>{}).catch(err=>{})
where 查询条件
get 获取查询
在小程序中将数据保存data有一个专用的方法
this.ssetData({
属性名:新值
})