# db.command.and

Query command. Describes the logical "and" relationship, indicating that multiple query filter conditions need be met at the same time.

Sample code

Filter out todos whose progress is greater than 50 and less than 100:

Streaming writing:

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)
  }
}

Pre-writing:

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)
  }
}
点击咨询小助手