note 97539 added to mongo.tutorial
| From: | php at whoah dot net | Date: | Sun, 25 Apr 2010 05:57:19 +0000 |
| Subject: | note 97539 added to mongo.tutorial | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-168611@lists.php.net to get a copy of this message | ||
Make sure array keys consecutive before inserting. As of 1.0.6 driver, the following will end up as
an object of key:value pairs, instead of an array, because it's trying to maintain the 0 and 2
keys:
$array = array('a', 'b', 'c');
unset($array[1]);
$document = array(
'embedded' => $array,
);
// assuming local
$mongo = new Mongo();
$mongo->test->test->insert($document);
mongodb result:
{ "_id" : ObjectId(...), "embedded" : { "0" : "a",
"2" : "c" } }
This is bad if you plan on indexing the embedded property as an array because objects and arrays are
indexed differently.
Whether the behaviour will change or not, this is logged here: http://jira.mongodb.org/browse/PHP-104
If you know about it, it's not major, just use a sort() before inserting, or use array_*
methods to remove elements instead of unset() -- anything that will re-adjust keys.
----
Server IP: 69.147.83.197
Probable Submitter: 203.158.45.230
----
Manual Page -- http://www.php.net/manual/en/mongo.tutorial.php
Edit -- https://master.php.net/note/edit/97539
Del: integrated -- https://master.php.net/note/delete/97539/integrated
Del: useless -- https://master.php.net/note/delete/97539/useless
Del: bad code -- https://master.php.net/note/delete/97539/bad+code
Del: spam -- https://master.php.net/note/delete/97539/spam
Del: non-english -- https://master.php.net/note/delete/97539/non-english
Del: in docs -- https://master.php.net/note/delete/97539/in+docs
Del: other reasons-- https://master.php.net/note/delete/97539
Reject -- https://master.php.net/note/reject/97539
Search -- https://master.php.net/manage/user-notes.php