duanlongnao0028 2013-11-20 05:53
浏览 19

php中的mongo $无效

I am trying to get the following mongo query work using PHP.

$users = array(26549,42852);

        $db_mon_con = $mon_con->main;
        $collection = $db_mon_con->main_a;


  $cursor = $collection->find(array('userid' => 
                                    array('$in' => $users)
                                  )
                                  );

One of the documents that should be returned looks like this :

{
"_id" : ObjectId("5284ef9a47ee3f45c73546f8"),
"id" : "22523",
"invitations" : [{
  "employerid" : "1481",
  "jobid" : "6272",
  "createdon" : "2013-09-10 21:31:39",
  "updatedon" : "2013-09-16 08:59:13",
  "status" : "rejected",
  "remarks" : "no activity"
}],
"name" : "ss",
"profilecompletion" : 0,
"userid" : "26549"
}
  • 写回答

1条回答 默认 最新

  • douli4852 2013-11-20 06:15
    关注

    You do have a type mismatch: you are passing in integers to your query, but the userid stored in mongo are strings ("userid" : "26549" as opposed to "userid" : 26549). You'll need to convert your integers to strings before you query using them:

    $users = array("26549","42852");
    

    Alternatively, you could make sure that wherever you're inserting the userid, you insert it as a proper integer.

    评论

报告相同问题?

悬赏问题

  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法