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

SDK database Command query,comparison operator


May 20, 2021 WeChat Mini Program Development Document


Table of contents


Command.eq(value: any): Command

Support: small programs, cloud functions, web

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.

Parameters

value: any

Returns a value

Command

Instructions for use

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

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

You can also use instructions:

const _ = db.command
const openID = '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'
  })
})

Command.neq(value: any): Command

Support: small programs, cloud functions, web

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

Parameters

value: any

Returns a value

Command

Instructions for use

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


Command.lt(value: any): Command

Support: small programs, cloud functions, web

The query filter operator, which means that it needs to be less than the specified value. Date objects can be passed in for date comparison.

Parameters

value: any

Returns a value

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

Command.lte(value: any): Command

Support: small programs, cloud functions, web

Query filter operator, which means that the specified value needs to be less than or equal to. Date objects can be passed in for date comparison.

Parameters

value: any

Returns a value

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

Command.gt(value: any): Command

Support: small programs, cloud functions, web

The query filter operator, which means that it needs to be greater than the specified value. Date objects can be passed in for date comparison.

Parameters

value: any

Returns a value

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

Command.gte(value: any): Command

Support: small programs, cloud functions, web

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

Parameters

value: any

Returns a value

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

Command.in(value: any[]): Command

Support: small programs, cloud functions, web

The query filter operator, which means that the required value is within a given array.

Parameters

value: any[]

Returns a value

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

Command.nin(value: any[]): Command

Support: small programs, cloud functions, web

The query filter operator, which means that the required value is not in a given array.

Parameters

value: any[]

Returns a value

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