Doctrine MongoDB ODM 在两个或多个字段中搜索
我想在 Doctrine Mongo ODM 中编写一个查询,通过正则表达式在两个或多个字段中进行搜索。在 SQL 中,它看起来像:
SELECT * FROM user WHERE name LIKE %search% OR surname LIKE %search%;
我可以为一个字段编写一个查询,如下所示:
$qb->field('surname')->equals(new \MongoRegex('/.*'.$this->search.'.*/i'));
但当我尝试搜索更多字段时,我不知所措。
感谢您的帮助
I would like to write a query in Doctrine Mongo ODM that searches by regex in two or more fields. In SQL it would look like:
SELECT * FROM user WHERE name LIKE %search% OR surname LIKE %search%;
I can write a query for one field like this:
$qb->field('surname')->equals(new \MongoRegex('/.*'.$this->search.'.*/i'));
but I'm at a loss when i try to search in more fields.
Thanks for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
其实很简单,我在发布这个问题后 5 分钟就发现了
well actually it is quite simple, i found out 5 mins after posting this question
您需要使用 $or 运算符。我不确定这在理论上是如何完成的,但您正在 shell 中寻找与此等效的内容:
You need to use the $or operator. I'm not sure how this is done in doctrine but you are looking for the equivalent of this in the shell: