1、普通模糊查询:查询结果中含有查询条件的数据
db.collection('idiom').where({
name: {
// 模糊查询参数
$regex: e.detail.value + '.*',
// $regex: '^' + e.detail.value + '.*',
//不区分大小写
$options: 'i'
}
}).field({
name: true,
description: true,
_openid: true,
_id: true
})
上图查询的结果,无论是首字母还是中间或者结尾的有“没”的都查出来了。
来看看下面的首字母查询
2、首字母模糊查询
db.collection('idiom').where({
name: {
// 模糊查询参数
// $regex: e.detail.value + '.*',
$regex: '^' + e.detail.value + '.*',
//不区分大小写
$options: 'i'
}
}).field({
name: true,
description: true,
_openid: true,
_id: true
})