在MongoDb和PHP中是否有等效的MySql getLastInsertID()?

The title asks it all. I have found an example that looked something like this:

db.find(fields = {"-id"}).sort("-id", -1).limit(X)

but that doesn't seem safe because that is assuming the ids will actually be in order.

$item = array( ... );
$mongo_collection->insert($item);
$id = $item['_id'];

It'll add the ID to the $item array. Also note you can use an object instead of an array if it's your preference.