云数据库中某字段类型为string,如何在查询中使用where语句筛选该字段包含指定子串的记录?
发布于 7 年前 作者 fugang 7601 次浏览 来自 官方Issues

例如针对记录:

{    title: “abcdefd”

    num: 4

}

想要用where条件筛选title字段包含指定子串如"cde"的记录,该如何编写条件呢?

2 回复

db.collection(‘xxxx’).where({

    title: /(.*)?cde(.*)?/i

}).get()

或者

db.collection(‘xxxx’).aggregate()

.addFields({

    matched: $.gte([$.indexOfCP([’$title’, ‘cde’]), 0])

})

.match({

    matched: !0

})

.end()

大佬有解答,膜拜

回到顶部