db.command.and

查询指令,用于表示逻辑 "与" 的关系,表示需同时满足多个查询筛选条件

示例代码

如筛选出进度大于 50 小于 100 的 todo:

流式写法:

  1. const cloud = require('wx-server-sdk')
  2. cloud.init()
  3. const db = cloud.database()
  4. const _ = db.command
  5. exports.main = async (event, context) => {
  6. try {
  7. return await db.collection('todo').where({
  8. progress: _.gt(50).and(_.lt(100))
  9. }).get()
  10. } catch(e) {
  11. console.error(e)
  12. }
  13. }

前置写法:

  1. const cloud = require('wx-server-sdk')
  2. cloud.init()
  3. const db = cloud.database()
  4. const _ = db.command
  5. exports.main = async (event, context) => {
  6. try {
  7. return await db.collection('todo').where({
  8. memory: _.and(_.gt(50), _.lt(100))
  9. }).get()
  10. } catch(e) {
  11. console.error(e)
  12. }
  13. }

原文: https://developers.weixin.qq.com/miniprogram/dev/wxcloud/reference-server-api/database/command.and.html