添加查询条件
collection.where()参数 设置过滤条件where 可接收对象作为参数,表示筛选出拥有和传入对象相同的 key-value 的文档。比如筛选出所有类型为计算机的、内存为 8g 的商品:
db.collection('goods').where({ category: 'computer', type: { memory: 8, }})
如果要表达更复杂的查询,可使用高级查询指令,比如筛选出所有内存大于 8g 的计算机商品:
const dbCmd = db.command // 取指令db.collection('goods').where({ category: 'computer', type: { memory: dbCmd.gt(8), // 表示大于 8 }})
where 可以使用正则表达式来查询文档,比如一下示例查询所有name字段以ABC开头的用户
db.collection('user').where({ name: new RegExp('^ABC')})
