![](/img/trans.png)
[英]Doctrine. Why i get persistentCollection and an empty array on ManyToMany?
[英]MongoDB and Doctrine. How to search text in array?
一些mongo文档用户包含嵌入式文档Message的数组,其中包含一些字符串成员'text':
/**
* @MongoDB\EmbeddedDocument
*/
class Message {
/**
* @MongoDB\Field(type="string")
*/
protected $text;
}
/**
* @MongoDB\Document(collection="chats")
* @JMS\ExclusionPolicy("none")
*/
class User {
/**
* @MongoDB\EmbedMany(targetDocument=myBundle\Document\Message", strategy="addToSet")
*/
protected $messages = array();
}
如何在datbaase中为所有用户的message.text搜索一些子字符串? 因此,如果某人收到消息“ Hello Bob!”,则可以通过搜索“ Bob”找到该消息。
您是否尝试过类似的方法:
$product = $this->get('doctrine_mongodb')
->getManager()
->createQueryBuilder('YourOwnBundle:User')
->field('messages.text')->equals(new \MongoRegex('Bob'))
;
如果您想对这种请求有一些表现,请记住使用全文索引!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.