db.command.and
查询指令,用于表示逻辑 "与" 的关系,表示需同时满足多个查询筛选条件
示例代码
如筛选出进度大于 50 小于 100 的 todo:
流式写法:
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
const _ = db.command
exports.main = async (event, context) => {
try {
return await db.collection('todo').where({
progress: _.gt(50).and(_.lt(100))
}).get()
} catch(e) {
console.error(e)
}
}
前置写法:
const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
const _ = db.command
exports.main = async (event, context) => {
try {
return await db.collection('todo').where({
memory: _.and(_.gt(50), _.lt(100))
}).get()
} catch(e) {
console.error(e)
}
}