Mongodb php get id of new document?

后端 未结 4 1291
不知归路
不知归路 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:10

     $newDocument = $db->collection->findAndModify ( $row, $row, null, array('new'=>true,'upsert' => true));
     $strId = $newDocument['_id']->{'$id'};
    

    http://php.net/manual/en/mongocollection.findandmodify.php

提交回复
热议问题