【问题标题】:How can i get the object id from loop in mongodb如何从 mongodb 的循环中获取对象 ID
【发布时间】:2022-06-14 21:50:27
【问题描述】:

所以我想使用 foreach 循环从 mongodb 中获取对象 id。我该如何实现呢?

$cursor2 = $videoCollection->find(['$text' => ['$search' => 'C:/Users/']]);

$cursorArray = json_decode(json_encode($cursor2->toArray(),true));

 foreach ($cursorArray as $key=>$document) {
   print_r($document->_id);
}

如何从中获取对象 ID?

 [_id] => stdClass Object
        (
            [$oid] => 6246c1c3b5ad6657936980b3
        )

【问题讨论】:

  • 你为什么编码 JSON 只是为了在同一行中解码它?

标签: php mongodb


猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-09
  • 1970-01-01
  • 2017-05-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多