Mongodb的PHP获取新文件的ID? [英] Mongodb php get id of new document?

查看:60
本文介绍了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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆