MongoDB+Doctrine How to use find with pattern matching

南笙酒味 提交于 2019-12-11 10:29:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!