【问题标题】:php and mongo db find doc by name and text legnthphp 和 mongodb 按名称和文本长度查找文档
【发布时间】:2015-12-12 12:48:03
【问题描述】:

您好,我需要有关 php 和 mongo db 的帮助。 我的服务器中有这样的文档:

comment: "aaaaaa"
id: "11111"
_id: {$id: "564c5a297efcf0181d00002c"}
active: true
flag: 7

我需要给它一些 id

$ids = "5555,3333,2222,11111"

我需要在我的文档中搜索具有此 ID 的所有结果 我这样做:

$query = array("id" => array('$in'=> $where));

它工作正常,但现在我需要添加另一个条件。

我需要在我的文档中找到所有的 id,但那个也有

"active" => true,
"comment.length" > 2

所以 rusult 查询将给我所有具有 id && active = true && comment.length > 2 之一的文档 我设法找到了 active 和 comment.length 的解决方案:

    $jsCond = "function() {
    return this.comment.length > 2 && this.active == true ;
    }";

但是不知道如何让它运作良好。

我需要帮助!!谢谢!

【问题讨论】:

标签: php arrays mongodb mongodb-query


【解决方案1】:

我已经解决了:

$jsCond = "function() {  return this.comment.length > 2 && this.active == true ; }";

$query2 = array( '$and' => array(
    array("id" => array('$in'=> $where)),
    array('$where' => $jsCond )
));

【讨论】:

    猜你喜欢
    • 2021-09-20
    • 2021-05-08
    • 1970-01-01
    • 2015-05-03
    • 2021-07-05
    • 2011-06-14
    • 1970-01-01
    • 2021-11-20
    • 1970-01-01
    相关资源
    最近更新 更多