比赛条件前忽略特殊字符 [英] Ignore special characters before match conditions
本文介绍了比赛条件前忽略特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我该如何在mongo中编写以下等效项?在检查条件之前,我需要忽略特定列中的某些字符(空格,连字符).为了举一个mysql的例子,我只是删除空间.
How can I write equivalent of following in mongo? I need to ignore some characters(spaces, hyphen) from a particular column before conditions are checked. For the sake of putting an example of mysql I am just removing space.
select * from TABLE
where REPLACE('name', ' ', '') = 'TEST'
因此,如果名称列具有应匹配的"T E S T".
So if name column has " T E S T" that should match.
推荐答案
您可以在查询中尝试使用$where
运算符:
You can try with $where
operator in your query:
{$where: "this.name.replace(/[ -]/g,'') == 'TEST'"}
或:
{$where: "this.name.match(/T[ -]*E[ -]*S[ -]*T/)"}
或直接$regex
:
{name: /T[ -]*E[ -]*S[ -]*T/}
有关 $where
More info about $where
$regex
operators.
这篇关于比赛条件前忽略特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文