小程序云开发-多字段或查询实现
灵活运用 and or 符号
step1:
外层查询使用 and
step2:
内层查询使用 or
关键代码如下:
const app = getApp(); const db = wx.cloud.database(); const _ = db.command;
查询:发布类型 && 订单状态 &&(申请者openid || 订单者的 openid)
getMyAllOrders() { let _this = this; let openid = app.globalData.openid; db.collection('order_info').where(_.and([{ publish_type: '1' }, { order_status: _.eq('2') }, _.or([{ _openid: openid }, { order_openid: openid } ]) ])).get().then(res => { console.log(res) }) },
效果如下图