PHP& MONGO:嵌套查找查询$和$或$ ne

时间:2013-11-26 18:05:15

标签: php regex mongodb count find

我正在尝试查询我想要检索查询数据库中字段的项目。 我需要检查一下如下(例子):

检索文本字段包含“足球”或“篮球”的书籍:

我想要的项目只在上面的人口中:

包含'1989'

排除'欧洲'

有什么想法吗?我现在正在计算,但它不起作用:

    //search words
    foreach ($cardSearch as $value) {
        $regexSearch[]['text'] = new MongoRegex("/" . $value . "/");
    }

    //words included
    foreach ($cardInclu as $value) {
        $regexInclu[]['text'] = new MongoRegex("/" . $value . "/");
    }

    //words excluded
    foreach ($cardExlu as $value) {
        $regexExclu[]['text'] = new MongoRegex("/" . $value . "/");
    }

    $arr['$and'] = $regexInclu;
    $arr['$ne'] = $regexExclu;
    array_push($regexSearch, $arr);

    $i = $mongoCollection->count(array('$or' => $regexSearch));

    $i = $mongoCollection->count(array('$or' => $regexSearch, 
         '$and' => $regexInclu, '$ne' => $regexExclu));

谢谢!

0 个答案:

没有答案