keyword = '' post = collection.find({ 'key': '/^' + keyword })
如上面的代码所示,当keyword包含一些正则符号,比如$之类时,查询结果就不准确了。 不知道mongodb有没有内置转义的方法,还是说必须要外部对keyword进行转义?
$
小伙看你根骨奇佳,潜力无限,来学PHP伐。
Mongodb’s regular expression query has two formats One is {key:{$regex:".*"}} The other is {key:/.*/} For the first escape use \ The second use
Mongodb’s regular expression query has two formats
One is {key:{$regex:".*"}}
The other is {key:/.*/}
For the first escape use \
The second use