mongo中的_id是一个objectid对象类型,不管是查询时作为条件,还是列表时展示内容,都需要进行一下抓换
查询时要转为objectid对象
列表时要把对象转成字符串覆盖回_id字段
$filter['_id']=new MongoDBBSONObjectId($params['id']);; $options=[]; $collect='.modelHis'; $mongoManger = new MongoDBDriverManager("mongodb://127.0.0.1:27017"); $query = new MongoDBDriverQuery($filter, $options); $cursor = $mongoManger->executeQuery($dbName.$collect, $query); if($cursor->isDead()){ //return []; } $items=[]; foreach ($cursor as $document) { $document->_id=$document->_id->__toString(); $items[]=get_object_vars($document); }