Database.RegExp
构造正则表达式,仅需在普通 js 正则表达式无法满足的情况下使用
Command.or(expressions: any[])
查询操作符,用于表示逻辑 “或” 的关系,表示需同时满足多个查询筛选条件。或指令有两种用法,一是可以进行字段值的 “或” 操作,二是也可以进行跨字段的
“或” 操作。
Command.and(expressions: any[])
查询操作符,用于表示逻辑 “与” 的关系,表示需同时满足多个查询筛选条件

<>1、模糊搜索单个字段

代码解释:搜索 描述(description)中包含“今天”的数据
db.collection('findLostInfo').where({ description: db.RegExp({ regexp: '今天',
options: 'i',//大小写不区分 }) }).get()
<>2、模糊搜索多个字段(只满足一个条件即可)

代码解释:搜索 描述(description)中包含“今天” 或 类型(type)中包含“found”的数据
const _ = db.command; db.collection('findLostInfo').where(_.or( [{ description:
db.RegExp({ regexp: '今天', options: 'i', //大小写不区分 }) }, { type: db.RegExp({
regexp: 'found', options: 'i', //大小写不区分 }) } ])).get() });
<>3、模糊搜索多个字段(同时满足多个条件)

代码解释:搜索 描述(description)中包含“今天” 且 类型(type)中包含“lost”的数据
const _ = db.command; db.collection('findLostInfo').where(_.and( [{ description
: db.RegExp({ regexp: '今天', options: 'i', //大小写不区分 }) }, { type: db.RegExp({
regexp: 'lost', options: 'i', //大小写不区分 }) } ])).get().then(res => { console.log(
res); });

技术
下载桌面版
GitHub
百度网盘(提取码:draw)
Gitee
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:766591547
关注微信