关于unicloud-db组件的增删改查
add增加写法
add() {
const db = uniCloud.database();
console.log(this.rooms.name)
db.collection("rooms").add(this.rooms).then(e => {
console.log(e)
})
},
查询
this.$db.collection("rooms").where({
name: this.rooms.name
}).get().then(res => {
console .log(res)
}
查询所有数据以及获取数量
let da = this.$db.collection('pro-user').get().then((res) => {
console.log(res.result.data.length)
});
通过ID进行修改
delete this.info._id;
this.$db.collection('system-settings').doc('661f1f738620667bb4349491').update(this.info).then(e => {
uni.hideLoading()
uni.showToast({
title: '设置成功'
})
})
doc:根据唯一索引(_id)进行修改数据。
where:根据提供的筛选条件进行修改数据。
两种方式皆可
删除
remove(id) {
this.$refs.udb.remove(id)
}
上面的$refs.udb与unicloud-db绑定的
<unicloud-db ref="udb" v-slot:default="{data, loading, error, options}" collection="whizzing">
</unicloud-db >