Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat small program cloud development service-side database API specifies the filter criteria


May 20, 2021 WeChat Mini Program Development Document


Table of contents


Collection.where

Specify the filter

The method signature is as follows:

function where(rule: object): Query

The method accepts a required object parameter rule, which defines the filter criteria

The sample code

Find to-dos for Unfinished Progress 50:

const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()
exports.main = async (event, context) => {
  try {
    return await db.collection('todos').where({
      done: false,
      progress: 50
    })
    .get()
  } catch(e) {
    console.error(e)
  }
}