Mongodb php get id of new document?

后端 未结 4 1286
不知归路
不知归路 2020-12-29 19:39

Creating a document:

$db->collection->insert($content);
// $newDocID = ???

I\'m trying to get the new document\'s id. How? Thanks.

4条回答
  •  鱼传尺愫
    2020-12-29 20:15

    According to the docs the array you pass to insert will be amended with an _id field:

    $db->collection->insert($content);
    $newDocID = $content['_id'];
    

提交回复
热议问题