12
我想在文檔中搜索具有特殊字符的值,如" $/. @ > "
。在MongoDB文檔中搜索帶有特殊字符的字符串
讓我們考慮,我一直用的myKey像值"test$australia", "test$austria", "test$belgium", "green.africa".
我想與'.*$aus.*',
例如搜索值,
db.myCollection.find({ myKey : /.*$aus.*/i });
OR
db.myCollection.find({ myKey : { '$regex' : '.*$aus.*','$options' : 'i' });
以上查詢不工作,浩我應該形成查詢嗎? 我正在使用MongoDB 2.4.1。
請問您可以刪除在控制檯中不需要的qr操作符..我也編輯了問題。它確實有效。 – dex
另外我怎樣才能達到與REGEX選項相同。 – dex
您必須在mongo json查詢中的正則表達式字符串中加上反斜槓:'db.myCollection.find({myKey:{$ regex:'。* \\ $ aus。*',$ options:'i'}} )' –