【发布时间】:2013-01-09 09:43:58
【问题描述】:
我正在使用 PHP 连接 MongoDB。我的代码如下。
// connect
$m = new MongoClient($con_string); // connect to a remote host at a given port
$db = $m->main;
$customers = $db->customer->find();
我想将 $customers 集合作为 json 文档返回到我的 HTML。我该怎么做?
【问题讨论】:
-
foreach($customers as $k => $row){ $newa[] = json_encode($row); }您可能需要先将对象类型转换为纯字符串,尽管像MongoId