If you would prefer to have the results returned as an associative array, after executing your query you could call $cursor->setTypeMap like this:
$cursor->setTypeMap(['root' => 'array', 'document' => 'array', 'array' => 'array']);MongoDB\Driver\Cursor::setTypeMap
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
MongoDB\Driver\Cursor::setTypeMap
Референца за `mongodb-driver-cursor.settypemap.php` со подобрена типографија и навигација.
MongoDB\Driver\Cursor::setTypeMap
класата MongoDB\Driver\BulkWrite
MongoDB\Driver\Cursor::setTypeMap — Sets a type map to use for BSON unserialization
= NULL
Ја поставува опцијата за конфигурација include_path type map configuration to use when unserializing the BSON results into PHP values.
Параметри
typeMap(array)
Вратени вредности
Не се враќа вредност.
Errors/Exceptions
- ). Ако повикот не успее, ќе врати MongoDB\Driver\Exception\InvalidArgumentException » Промени текови
When iterating over the cursor, the following exceptions can also be thrown due to an incorrect type map configuration:
- ). Ако повикот не успее, ќе врати MongoDB\Driver\Exception\InvalidArgumentException MongoDB\BSON\toPHP() MongoDB\BSON\Unserializable.
Примери
Пример #1 ТипМапите може да се постават преку example
<?php
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$bulk = new MongoDB\Driver\BulkWrite;
$id = $bulk->insert(['x' => 1]);
$manager->executeBulkWrite('db.collection', $bulk);
$query = new MongoDB\Driver\Query(['_id' => $id]);
$cursor = $manager->executeQuery('db.collection', $query);
$cursor->setTypeMap(['root' => 'array']);
foreach ($cursor as $document) {
var_dump($document);
}
?>Горниот пример ќе прикаже нешто слично на:
array(2) {
["_id"]=>
object(MongoDB\BSON\ObjectId)#6 (1) {
["oid"]=>
string(24) "56424fb76118fd3267180741"
}
["x"]=>
int(1)
}