通过db.command获取
const db = wx.cloud.database();
const _ = db.command; //属性
一、command的比较操作符
- eq 等于
- neq 不等于
- lt 小于
- lte 小于等于
- gt 大于
- gte 大于等于
- in 要求在数组内的
- nin 要求不在数组内的
以下例子中,hist是一个表示点击次数的变量
getData(){
db.collection("demolist")
.where({
hist:_.eq(12) //查询点击次数为12的数据,neq同理
})
.get()
.then(res=>{
console.log(res)
//渲染到前端
this.setData({
dataList:res.data
})
})
},
in和nin要求值在给定的数组内
.where({
hist:_.in([12,55]) //查询点击次数为12和55的数据
})
注意: in、nin里的数组不是范围,是精确
二、command的逻辑操作符
(1)and和or
1、查询单个字段
需要传入多个查询操作符或常量,表示字段需满足或匹配给定的条件。
eg:hist字段值大于20且小于30
.where({
hist:_.and(_.gt

本文介绍了微信小程序云开发中使用command进行数据库操作,包括比较操作符如eq、lt等,逻辑操作符如and、or、not,字段操作符exists和mod,以及数组操作符all、elemMatch、size。此外,还讲解了与update配合使用的更新操作符,如inc、remove、set等。
—command 数据库操作符&spm=1001.2101.3001.5002&articleId=120604447&d=1&t=3&u=c8665f6383404e9cb2ed4eb7cf00baeb)
4199

被折叠的 条评论
为什么被折叠?



