note 119603 added to mongodb-bson-objectid.tostring
| From: | JaredC. | Date: | Thu, 14 Jul 2016 15:31:30 +0000 |
| Subject: | note 119603 added to mongodb-bson-objectid.tostring | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-206006@lists.php.net to get a copy of this message | ||
I found I had to manually call the __toString method when I was trying to populate an associative
array of mongoguid => stringValue:
$filter = [];
$options = [];
$this->propertyMap = [];
try {
$query = new \MongoDB\Driver\Query($filter, $options);
$cursor = $this->mongo->executeQuery('MyDbName.MyColectionName',
$query);
} catch (Exception $e) {
echo "Mongo Query failure pulling the collection" . PHP_EOL;
echo($e->getMessage());
die("aborting");
}
foreach ($cursor as $property) {
//$this->propertyMap[$property->{_id}->__toString()] = $property->name;
$this->propertyMap[$property->name] = $property->{_id}->__toString();
}
You could also do it as $property->{_id} . "" to get the same string result. Otherwise
you end up with an array of MongoDB\BSON\ObjectID objects.
----
Server IP: 72.52.91.14
Probable Submitter: 207.67.35.226
----
Manual Page -- http://php.net/manual/en/mongodb-bson-objectid.tostring.php
Edit -- https://master.php.net/note/edit/119603
Del: integrated -- https://master.php.net/note/delete/119603/integrated
Del: useless -- https://master.php.net/note/delete/119603/useless
Del: bad code -- https://master.php.net/note/delete/119603/bad+code
Del: spam -- https://master.php.net/note/delete/119603/spam
Del: non-english -- https://master.php.net/note/delete/119603/non-english
Del: in docs -- https://master.php.net/note/delete/119603/in+docs
Del: other reasons-- https://master.php.net/note/delete/119603
Reject -- https://master.php.net/note/reject/119603
Search -- https://master.php.net/manage/user-notes.php