我正在使用mongodb,而我的查找结果是这个
> db.analysis.find().pretty()
{ "_id" : "a", "age" : [ "d" ] }
{ "_id" : "b", "age" : [ "a", "b", "e" ] }
这是我在php中使用的查询:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$mng = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$bulk = new MongoDB\Driver\BulkWrite;
$query = new MongoDB\Driver\Query([]);
$rows = $mng->executeQuery("whot.analysis", $query);
$return_array = array();
foreach ($rows as $row) {
array_push($return_array,
array(
"_id" => "$row->_id",
"age" => "$row->age"
));
}
$json= json_encode($return_array);
echo $json;
结果
Notice: Array to string conversion in /usr/local/nginx/html/mongo_analysis.php on line 39
Notice: Array to string conversion in /usr/local/nginx/html/mongo_analysis.php on line 39
[{"_id":"a","age":"Array"},{"_id":"b","age":"Array"}]
任何人都可以让我知道如何更改代码吗?
我想将Array更改为字符串。