MongoDB\BSON\ObjectID::__toString

(mongodb >=1.0.0)

MongoDB\BSON\ObjectID::__toStringDescription

Опис

public ReturnType MongoDB\BSON\ObjectID::__toString ( void )

Параметри

В цієї функції немає параметрів.

Значення, що повертаються

Помилки/Винятки

Приклади

Приклад #1 MongoDB\BSON\ObjectID::__toString() example

<?php

/* ... */

?>

Наведений вище приклад виведе щось подібне до:

...

Прогляньте Також

add a note add a note

User Contributed Notes 1 note

up
0
Jared C.
7 years ago
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.
To Top