May 20, 2021 WeChat Mini Program Development Document
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.
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'
})
})
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.
Indicates that the field is not equal to a value, as opposed to eq
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.
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
})
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.
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
})
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.
Find todos with progress greater than 50
const _ = db.command
db.collection('todos').where({
progress: _.gt(50)
})
.get({
success: console.log,
fail: console.error
})
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.
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
})
Support: small programs, cloud functions, web
The query filter operator, which means that the required value is within a given array.
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
})
Support: small programs, cloud functions, web
The query filter operator, which means that the required value is not in a given array.
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
})