簡體   English   中英

MongoDB和學說。 如何搜索數組中的文本?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM