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

WeChat small program cloud development API query instructions


May 20, 2021 WeChat Mini Program Development Document


Table of contents


db.command.and

A query directive that represents the relationship between logical "and" and that multiple query filters need to be met at the same time

The sample code

If you filter out todos with a progress greater than 50 and less than 100:

Streaming:

const _ = db.command
db.collection('todo').where({
  progress: _.gt(50).and(_.lt(100))
})

Pre-writing:

const _ = db.command
db.collection('todo').where({
  memory: _.and(_.gt(50), _.lt(100))
})

db.command.or

A query directive that represents a logical "or" relationship that requires multiple query filters to be met at the same time. Or instructions can be used in two ways, between "or" for field values and for cross-field "or" operations.

The "or" action of a field value refers to specifying a field value as one of several values:

Field value or action: Sample code

If you filter out todos with progress greater than 80 or less than 20:

Streaming:

const _ = db.command
db.collection('todo').where({
  progress: _.gt(80).or(_.lt(20))
})

Pre-writing:

const _ = db.command
db.collection('todo').where({
  progress: _.or(_.gt(80), _.lt(20))
})

The pre-write method can also receive an array:

const _ = db.command
db.collection('todo').where({
  progress: _.or([_.gt(80), _.lt(20)])
})

Cross-field "or " action refers to a condition" or "" is equivalent to passing in more than one where statement to satisfy one of them, for example:

Cross-field or action: Sample code

If you filter out todos with progress greater than 80 or marked as completed:

const _ = db.command
db.collection('todo').where(_.or([
  {
    progress: _.gt(80)
  },
  {
    done: true
  }
]))