Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从PHP中的另一个数组中查找MongoDB数组中的子字符串_Php_Regex_Arrays_Mongodb_Find - Fatal编程技术网

从PHP中的另一个数组中查找MongoDB数组中的子字符串

从PHP中的另一个数组中查找MongoDB数组中的子字符串,php,regex,arrays,mongodb,find,Php,Regex,Arrays,Mongodb,Find,我在Mongo中保存了一个更复杂的文档“schema”,但我需要匹配的部分如下所示 "tags" : [ { "tag" : "accompong maroon festival", "type" : "label" }, { "tag" : "jamaica", "type" : "label" }, { "tag" : "maroon warrior", "

我在Mongo中保存了一个更复杂的文档“schema”,但我需要匹配的部分如下所示

"tags" : [
    {
        "tag" : "accompong maroon festival",
        "type" : "label"
    },
    {
        "tag" : "jamaica",
        "type" : "label"
    },
    {
        "tag" : "maroon warrior",
        "type" : "label"
    },
    {
        "tag" : "maroons",
        "type" : "label"
    },
    {
        "tag" : "caribbean culture",
        "type" : "label"
    },
    {
        "tag" : "rum",
        "type" : "label"
    }
}
我正在使用PHP查询Mongo数据库,我必须根据一组可能的单词来查询每个文档

array(
    'boxing',
    'warrior'
)
我不知道如何编写代码,以便尝试将我拥有的数组与保存在Mongo中的数据集相匹配。 现在我只想看看标签是否在单词数组中

$data = $this->event_model->find_by(
            array
            (
                'tags.tag' => array
                (
                    '$in' => $Words
                ),
                'published' => 'y'
            )
        );

我已经解决了这个问题,首先创建了一个使用MongoRegex搜索标记的数组,然后将该数组添加到$or过程中

        $or_array = array();
        foreach($Words as $w)
        {
            $or_array[] = array(
                'tags.tag' => new MongoRegex('/.*'. $w .'.*/i')
            );
        }

        $data = $this->event_model->find_by(
            array
            (
                '$or' => $or_array,
                'published' => 'y'
            )
        );