W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎勵
支持端:小程序 , 云函數(shù) , Web
查詢篩選條件,表示字段等于某個值。eq 指令接受一個字面量 (literal),可以是 number, boolean, string, object, array, Date。
比如篩選出所有自己發(fā)表的文章,除了用傳對象的方式:
const openID = 'xxx'
db.collection('articles').where({
_openid: openID
})
還可以用指令:
const _ = db.command
const openID = 'xxx'
db.collection('articles').where({
_openid: _.eq(openid)
})
注意 eq 指令比對象的方式有更大的靈活性,可以用于表示字段等于某個對象的情況,比如:
// 這種寫法表示匹配 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'
})
})
支持端:小程序 , 云函數(shù) , Web
查詢篩選條件,表示字段不等于某個值。eq 指令接受一個字面量 (literal),可以是 number, boolean, string, object, array, Date。
表示字段不等于某個值,和 eq 相反
支持端:小程序 , 云函數(shù) , Web
查詢篩選操作符,表示需小于指定值。可以傳入 Date 對象用于進(jìn)行日期比較。
找出進(jìn)度小于 50 的 todo
const _ = db.command
db.collection('todos').where({
progress: _.lt(50)
})
.get({
success: console.log,
fail: console.error
})
支持端:小程序 , 云函數(shù) , Web
查詢篩選操作符,表示需小于或等于指定值??梢詡魅?nbsp;Date 對象用于進(jìn)行日期比較。
找出進(jìn)度小于或等于 50 的 todo
const _ = db.command
db.collection('todos').where({
progress: _.lte(50)
})
.get({
success: console.log,
fail: console.error
})
支持端:小程序 , 云函數(shù) , Web
查詢篩選操作符,表示需大于指定值。可以傳入 Date 對象用于進(jìn)行日期比較。
找出進(jìn)度大于 50 的 todo
const _ = db.command
db.collection('todos').where({
progress: _.gt(50)
})
.get({
success: console.log,
fail: console.error
})
支持端:小程序 , 云函數(shù) , Web
查詢篩選操作符,表示需大于或等于指定值??梢詡魅?nbsp;Date 對象用于進(jìn)行日期比較。
找出進(jìn)度大于或等于 50 的 todo
const _ = db.command
db.collection('todos').where({
progress: _.gte(50)
})
.get({
success: console.log,
fail: console.error
})
支持端:小程序 , 云函數(shù) , Web
查詢篩選操作符,表示要求值在給定的數(shù)組內(nèi)。
找出進(jìn)度為 0 或 100 的 todo
const _ = db.command
db.collection('todos').where({
progress: _.in([0, 100])
})
.get({
success: console.log,
fail: console.error
})
支持端:小程序 , 云函數(shù) , Web
查詢篩選操作符,表示要求值不在給定的數(shù)組內(nèi)。
找出進(jìn)度不是 0 或 100 的 todo
const _ = db.command
db.collection('todos').where({
progress: _.nin([0, 100])
})
.get({
success: console.log,
fail: console.error
})
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: