无法访问记录的mongo id

时间:2018-04-13 10:25:58

标签: php mongodb mongodb-php php-mongodb

我正在尝试使用以下代码行来获取记录的mongo id

$query = ["role" => "admin", "uid" => (int) $this->set_reminder_user_id];
$cursor = $this->db->userTbl->find($query)->toArray();
$adminOId = $cursor['_id']['$oid'];

var_dump($cursor);
var_dump($adminOId);

光标的结果就像

array(1) { [0]=> object(MongoDB\Model\BSONDocument)#12 (1) { ["storage":"ArrayObject":private]=> array(8) { ["_id"]=> object(MongoDB\BSON\ObjectId)#10 (1) { ["oid"]=> string(24) "58e214a1113916d4290006c9" } ["uid"]=> float(1) ["username"]=> string(5) "admin" ["password"]=> string(6) "turkey" ["email_id"]=> string(22) "educiansuper@gmail.com" ["creation_date"]=> string(0) "" ["role"]=> string(5) "admin" ["is_enabled"]=> float(1) } } } 

抛出错误消息“Undefined index:_id in”

0 个答案:

没有答案