If you need to get the actual ID string, and you try the usual way, PHP will whine because it starts with a dollar sign and it thinks it's a variable. Instead, use this notation:
<?php
$mongoid->{'$id'} //Get the $id property of a MongoId object
?>
The MongoId class
Увод
A unique identifier created for database objects.
Синтаксис за класове
Съдържание
- MongoId::__construct — Creates a new id
- MongoId::__toString — Returns a hexidecimal representation of this id
alex dot turpin at gmail dot com
11-Jul-2011 09:15
sararschreiber at gmail dot com
12-Oct-2010 12:23
this is useful for querying for an object by id, given the id's hex:
<?php
$userid = '4cb4ab6d7addf98506010000';
$theObjId = new MongoId($userid);
$connection = new Mongo();
$db = $connection->thedb->users;
// this will return our matching entry.
$item = $db->findOne(array("_id" => $theObjId));
$connection->close();
?>
