note 96268 added to mongo.queries
| From: | jhuntwork at lightcubesolutions dot com | Date: | Wed, 17 Feb 2010 22:25:28 +0000 |
| Subject: | note 96268 added to mongo.queries | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-166095@lists.php.net to get a copy of this message | ||
If you have already converted the MongoID into a string elsewhere and need to query for an _id based
on the string, you can do so by creating a new MongoID object:
<?php
$m = new Mongo();
$collection = $collection = $m->selectDB('foo')->selectCollection('bar');
$id_string = '4b7c29908ead0e2e1d000000';
// The string is converted to a MongoID object
$mongo_id = new MongoID($id_string);
// $obj will be an array of data if the _id exists in the collection
$obj = $collection->findOne(array('_id'=>$mongo_id));
?>
----
Server IP: 69.147.83.197
Probable Submitter: 74.101.95.68
----
Manual Page -- http://www.php.net/manual/en/mongo.queries.php
Edit -- https://master.php.net/note/edit/96268
Del: integrated -- https://master.php.net/note/delete/96268/integrated
Del: useless -- https://master.php.net/note/delete/96268/useless
Del: bad code -- https://master.php.net/note/delete/96268/bad+code
Del: spam -- https://master.php.net/note/delete/96268/spam
Del: non-english -- https://master.php.net/note/delete/96268/non-english
Del: in docs -- https://master.php.net/note/delete/96268/in+docs
Del: other reasons-- https://master.php.net/note/delete/96268
Reject -- https://master.php.net/note/reject/96268
Search -- https://master.php.net/manage/user-notes.php