0

我正在尝试使用以下代码行获取记录的 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) } } } 

它抛出错误消息“未定义索引:_id in”

4

0 回答 0