我想搜索具有特殊字符的值,如? ! $/。 @>;
。
我想搜索诸如?test
之类的值,
例如,
db.myCollection.find({ myKey : /.*?test.*/i });
或
db.myCollection.find({ myKey : { '$regex' : '.*?test.*','$options' : 'i' });
在这里我该换什么?
您需要对特殊字符进行双重转义:
db.collection.find({
myKey: {
$regex: "\\?test",
"$options": "i"
}
})
https://mongoplayground.net/p/oarlsjvfng_