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 开发者_JS百科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.
精彩评论