本文介绍了Mongodb的PHP获取新文件的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建文档

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

我正在尝试获取新文档的ID.如何?谢谢.

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

推荐答案

根据 docs 传递给insert的数组将被修改为_id字段:

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

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

这篇关于Mongodb的PHP获取新文件的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:33
查看更多