我有以下代码:
<?php
require __DIR__ . '/vendor/autoload.php';
$client = new MongoDB\Client("mongodb://localhost:27017");
$collection = $client->bbcData->programmeData;
$result = $collection->find( [ '_id' => 'b007jwd9'] );
foreach ($result as $entry) {
echo $entry['_id'], ': ', $entry['complete_title'], "\n";
}
?>
JSON如下:
{"complete_title":{"name":"wimsey - murder must advertise","episode":"sudden decease of a man in dress clothes"},"media_type":"audio","_id":"b007jwd9","categories":{"category1":["drama", "crime"]}}
我想打印出complete_title的名称,但是文档没有显示这个的语法。目前,我收到一条错误消息,指出complete_title是一个BSONDocument,因此无法将其转换为String。
答案 0 :(得分:0)
使用a
获取数组。
iterator_to_array