MongoDB+Doctrine 如何使用带模式匹配的查找 [英] MongoDB+Doctrine How to use find with pattern matching

查看:34
本文介绍了MongoDB+Doctrine 如何使用带模式匹配的查找的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有学说的 Mongo DB.我想做如下的模式匹配

I am using Mongo DB with doctrine. I want to do pattern matching like below

db.user_logs.find({ "recipientName": /user1/i })

不使用MongoRegex

$qb->field('recipientEmail')->equals(new \MongoRegex('/.*'.$textToSearch.'.*/i'));

目的是在不创建类的情况下达成解决方案(如果可能)

purpose is to reach solution without creating class (if possible)

推荐答案

不确定这是最好的方法,但它有效:

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

$qb->where("function(){ var patt = /".$textToSearch."/i; return patt.test(this.recipientEmail);}");

这篇关于MongoDB+Doctrine 如何使用带模式匹配的查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆