0
我想从mongo db使用php获取记录。我正在尝试使用mongo集合中的_id字段来访问记录。但我无法获取相应的记录,我只能变为空。这是我正在使用的代码。使用PHP从mongo db获取基于“_id”的记录
$db = $this->Generalmodel->connect();
$collection = $db->listing;
$cursor = $collection->findOne(array("_id"=>$id));
var_dump($cursor);
我还与以下尝试过了,是没有用的太
$collection = $db->listing;
$cursor = $collection->find(array('$and' => array(array('_id' => $id), array('blocked' => "0"))));
foreach ($cursor as $obj)
var_dump($obj)
我失去了一些东西?
'$ id'的值是什么? – 2011-12-29 15:07:55
这是我从我的会话中获取的价值。基本上它是由mongo生成的_id,从我使用这个实体列表来选择关于单个实体的详细信息 – swordfish 2011-12-29 15:10:14
我的意思是,它是什么类型?实际的ObjectId,还是它转换为字符串? – 2011-12-29 15:12:12