# db.command.or

Query command. Describes the logical "or" relationship, indicating that at least one query filter is required to be met. The "or" command can be used in two ways: to perform an "or" operation on the value of a field, or to perform an "or" operation on the values of multiple fields.

The "or" operation on the value of a field is to specify one value of the field to one of multiple values:

Sample code of the "or" operation on the value of a field:

Filter out the todos whose progress is greater than 80 or less than 20:

Streaming writing:

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

In the pre-writing, an array may be alternatively received:

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

A cross-field "or" operation is an "or" condition equivalent to a condition in which at least one of multiple imported "where" statements is met. For example:

Sample code of the cross-field "or" operation:

Filter out the todos whose progress is greater than 80 or that have been completed:

const _ = db.command
db.collection('todo').where(_.or([
  {
    progress: _.gt(80)
  },
  {
    done: true
  }
]))
点击咨询小助手