mongo中的_id是一個objectid物件型別,不管是查詢時作為條件,還是串列時展示內容,都需要進行一下抓換
查詢時要轉為objectid物件
串列時要把物件轉成字串覆寫回_id欄位
$filter['_id']=new MongoDB\BSON\ObjectId($params['id']);; $options=[]; $collect='.modelHis'; $mongoManger = new MongoDB\Driver\Manager("mongodb://127.0.0.1:27017"); $query = new MongoDB\Driver\Query($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); }
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/80840.html
標籤:PHP
