问题
I am using Mongo DB with doctrine. I want to do pattern matching like below
db.user_logs.find({ "recipientName": /user1/i })
without using MongoRegex
class
$qb->field('recipientEmail')->equals(new \MongoRegex('/.*'.$textToSearch.'.*/i'));
purpose is to reach solution without creating class (if possible)
回答1:
Not sure this is the best way, but it works:
$qb->where("function(){ var patt = /".$textToSearch."/i; return patt.test(this.recipientEmail);}");
来源:https://stackoverflow.com/questions/27799938/mongodbdoctrine-how-to-use-find-with-pattern-matching