Searching string with special characters in MongoDB document -


i want search values having special characters such " $ / . @ > " in document.

lets consider, i've mykey values "test$australia", "test$austria", "test$belgium", "green.africa".

i want search values '.*$aus.*',

for example,

db.mycollection.find({ mykey : /.*$aus.*/i });  

or

db.mycollection.find({ mykey : { '$regex' : '.*$aus.*','$options' : 'i' }); 

above queries dont work , how should form query? i'm using mongodb 2.4.1.

you have escape $ \:

db.mycollection.find({ mykey : /.*\$aus.*/i });  // or db.mycollection.find({mykey: { $regex: '.*\\$aus.*', $options: 'i'}}) 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -