![](/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.