note 92207 modified in mongocollection.insert by danbrown
| From: | danbrown@php.net | Date: | Tue, 14 Jul 2009 14:43:25 +0000 |
| Subject: | note 92207 modified in mongocollection.insert by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-158277@lists.php.net to get a copy of this message | ||
Worth noting that insert() accepts the array by reference
On successful insert the array is returned with the _id assigned by Mongo
<?php
$doc = array(
'key1' => 'yay',
'key2' => 'yipee',
);
?>
therefore becomes:
<?php
$doc = array(
'key1' => 'yay',
'key2' => 'yipee',
'_id' => '4a5c9100fbecbc00503debc8'
);
?>
Handy. Akin to mysql's SELECT LAST_INSERT_ID() without the hassle of having to send another
query :-)
--was--
Worth noting that insert() accepts the array by reference
On successful insert the array is returned with the _id assigned by Mongo
$doc = array(
'key1' => 'yay',
'key2' => 'yipee',
);
therefore becomes:
$doc = array(
'key1' => 'yay',
'key2' => 'yipee',
'_id' => '4a5c9100fbecbc00503debc8'
);
Handy. Akin to mysql's SELECT LAST_INSERT_ID() without the hassle of having to send another
query :-)
http://php.net/manual/en/mongocollection.insert.php