【发布时间】:2016-06-18 13:33:46
【问题描述】:
我在从 MongoDB 数据库中检索 ObjectID 时遇到问题,但是当通过 json_encode 运行时,“_id”值总是消失。我的数组中的所有其他数据都存在。我的代码是这样的:
$data = array('_id' => new MongoDB\BSON\ObjectID(), 'title' => 'abc123');
//ID Is there!
print_r($data);
//ID IS EMPTTYy!!!
print_r(json_encode($data));
exit();
结果如下所示:
Array ( [_id] => MongoDB\BSON\ObjectID Object ( [oid] => 56d9d2687e34d70d3a304c46 ) [title] => abc123 )
{"_id":{},"title":"abc123"}
至少,_id 中应该有一个对象或数字。我的问题是什么剥离了 \MongoDB\BSON\ObjectID,我怎样才能让它留下来?
【问题讨论】:
-
请发布你得到的输出,以及你期望的输出。
-
好的,发布输出