MongoDB+Doctrine How to use find with pattern matc

2019-07-29 12:40发布

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条回答
我命由我不由天
2楼-- · 2019-07-29 13:13

Not sure this is the best way, but it works:

$qb->where("function(){ var patt = /".$textToSearch."/i; return patt.test(this.recipientEmail);}");
查看更多
登录 后发表回答