note 103220 added to mongocollection.insert

From: Date: Fri, 01 Apr 2011 16:54:27 +0000
Subject: note 103220 added to mongocollection.insert
Groups: php.notes 
Request: Send a blank email to php-notes+get-178413@lists.php.net to get a copy of this message
Also worth noting is that the MongoCollection::insert() method accepts objects as the first argument as well as arrays. <?php $data = new stdClass; $data->foo = 'foo'; $data->bar = 'bar'; $collection->insert($data); var_dump($data->_id); // An instance of MongoId ?> You can use other classes as well, but MongoCollection::insert() will fail if the object contains any protected or private properties. Public properties listed in the class will also be inserted: <?php class SomeClass { public $foo = 'bar'; public $bar = 'foo'; } $data = new SomeClass; $data->foobar = 42; $collection->insert($data); var_dump($data->_id); // An instance of MongoId ?> will result in a document with four elements: _id => some mongoid foo => 'bar' bar => 'foo' foobar => 42 ---- Server IP: 195.139.129.18 Probable Submitter: 80.203.237.142 ---- Manual Page -- http://www.php.net/manual/en/mongocollection.insert.php Edit -- https://master.php.net/note/edit/103220 Del: integrated -- https://master.php.net/note/delete/103220/integrated Del: useless -- https://master.php.net/note/delete/103220/useless Del: bad code -- https://master.php.net/note/delete/103220/bad+code Del: spam -- https://master.php.net/note/delete/103220/spam Del: non-english -- https://master.php.net/note/delete/103220/non-english Del: in docs -- https://master.php.net/note/delete/103220/in+docs Del: other reasons-- https://master.php.net/note/delete/103220 Reject -- https://master.php.net/note/reject/103220 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178413) next »