dongzou7134 2015-12-12 12:48
浏览 53

php和mongodb按名称和文本长度查找doc

hi i need help with php and mongo db . i have docs in my server like this:

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

i need to give it a sting of ids

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

and i need to search in my docs for all the result with this ids i do it like this:

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

its working ok but now i need to add anoter condition.

i need to find all the ids in my docs but the one that have also

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

so the rusult query wil give me all the docs that has one of the ids && active = true && comment.length > 2 i manage to find a solution for the active and comment.length with this:

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

but and dont have any idea how to make it work good.

i need help!! thanks!

  • 写回答

1条回答 默认 最新

  • donglian4770 2015-12-12 14:34
    关注

    i have solved it:

    $jsCond = "function() {  return this.comment.length > 2 && this.active == true ; }";
    
    $query2 = array( '$and' => array(
        array("id" => array('$in'=> $where)),
        array('$where' => $jsCond )
    ));
    
    评论

报告相同问题?

悬赏问题

  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答