蒙戈DB逃跑前斜线

问题描述:

如果集合(地区)的模板类似下面蒙戈DB逃跑前斜线

{ 
    'path': '/city/area/street/house' 
} 

那么我们该如何使用像查询这里(我如何逃脱前斜线)

db.getCollection('Area').find({ "path":/.city/area/street/house./}) 

这不工作

/.city\/area\/street\/house./

\将难逃/里面的正则表达式。

+0

db.getCollection( '区')。找到({“路径“:{'$ regex':'city \/area \/street \/house'}})这是有效的。谢谢!! –

它的工作使用正则表达式如下图所示,我们不需要逃避斜线

db.getCollection('Area').find({"path":{'$regex':'city/area/street/house'}}) 

这不起作用

db.getCollection('Area').find({ "path":/.city\/area\/street\/house./}) 
+0

如果你使用'$ regex',你还需要逃避斜线吗? –

+0

@SergioTulentsev斜杠不需要正则表达式,但使用转义斜杠也不会影响结果 –