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
Post a Comment