Search code examples
phpmongodbdoctrine-ormzend-framework2odm

How to use Reserved characters in createQueryBuilder and MongoRegix


i'm doing search with ZF2 Doctrine2 ODM and using MongoRegix but the problem is that i'm not able to search those terms which contains brackets like BS(Hons) is not searchable. my query is

$q->addOr($q->expr()->field($columns[$i]['field'])->equals(new \MongoRegex('/.*BS(Hons).*/i')));

any suggestion?


Solution

  • Reserved characters can be used in MongoRegx in the way.

    /.*BS/(Hons/).*/i
    

    the Query will be like this

    $q->addOr($q->expr()->field($field)->equals(new \MongoRegex('/.*BS/(Hons/).*/i')));