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

WeChat small program cloud development API query filtering criteria


May 20, 2021 WeChat Mini Program Development Document


Table of contents


db.command.eq

A query filter that means that a field is equal to a value. The eq instruction accepts a literal amount, which can be number, boolean, string, object, array, Date.

Method signature:

function eq(value: any): Command

For example, filter out all your own published articles, except in the form of a pass-through:

const myOpenID = 'xxx'
db.collection('articles').where({
  _openid: myOpenID
})

You can also use instructions:

const _ = db.command
const myOpenID = 'xxx'
db.collection('articles').where({
  _openid: _.eq(openid)
})

Note that eq instructions are more flexible than the way objects are used to indicate that a field is equal to an object, such as:

// 这种写法表示匹配 stat.publishYear == 2018 且 stat.language == 'zh-CN'
db.collection('articles').where({
  stat: {
    publishYear: 2018,
    language: 'zh-CN'
  }
})
// 这种写法表示 stat 对象等于 { publishYear: 2018, language: 'zh-CN' }
const _ = db.command
db.collection('articles').where({
  stat: _.eq({
    publishYear: 2018,
    language: 'zh-CN'
  })
})

db.command.neq

Indicates that the field is not equal to a value, as opposed to db.command.eq


db.command.lt

Query filters that indicate that the field needs to be less than the specified value. Date objects can be passed in for date comparison.

Method signature:

function lt(value: number | Date): Command

The sample code

Find todos with a progress of less than 50

const _ = db.command
db.collection('todos').where({
  progress: _.lt(50)
})
.get({
  success: console.log,
  fail: console.error
})

db.command.lte

A query filter that indicates that a field needs to be less than or equal to the specified value. Date objects can be passed in for date comparison.

Method signature:

function lte(value: number | Date): Command

The sample code

Find todos with progress of less than or equal to 50

const _ = db.command
db.collection('todos').where({
  progress: _.lte(50)
})
.get({
  success: console.log,
  fail: console.error
})

db.command.gt

Query filter, which means that the field needs to be greater than the specified value. Date objects can be passed in for date comparison.

Method signature:

function gt(value: number | Date): Command

The sample code

Find todos with progress greater than 50

const _ = db.command
db.collection('todos').where({
  progress: _.gt(50)
})
.get({
  success: console.log,
  fail: console.error
})

db.command.gte

A query filter that indicates that a field needs to be greater than or equal to the specified value. Date objects can be passed in for date comparison.

Method signature:

function gte(value: number | Date): Command

The sample code

Find todos with progress greater than or equal to 50

const _ = db.command
db.collection('todos').where({
  progress: _.gte(50)
})
.get({
  success: console.log,
  fail: console.error
})

db.command.in

A query filter that indicates that the value of a field needs to be within a given array.

Method signature:

function in(values: any[]): Command

The sample code

Find todos with a progress of 0 or 100

const _ = db.command
db.collection('todos').where({
  progress: _.in([0, 100])
})
.get({
  success: console.log,
  fail: console.error
})

db.command.in

A query filter that indicates that the value of a field needs to be not in a given array.

Method signature:

function nin(values: any[]): Command

The sample code

Find out if the progress is not 0 or 100 todo

const _ = db.command
db.collection('todos').where({
  progress: _.nin([0, 100])
})
.get({
  success: console.log,
  fail: console.error
})