PHPLIB-530: Fix missing ns entry for idIndex in collection info

parent a1af3588
......@@ -18,6 +18,7 @@
namespace MongoDB\Model;
use IteratorIterator;
use Traversable;
/**
* CollectionInfoIterator for listCollections command results.
......@@ -32,6 +33,19 @@ use IteratorIterator;
*/
class CollectionInfoCommandIterator extends IteratorIterator implements CollectionInfoIterator
{
/** @var string|null */
private $databaseName;
/**
* @param string|null $databaseName
*/
public function __construct(Traversable $iterator, $databaseName = null)
{
parent::__construct($iterator);
$this->databaseName = $databaseName;
}
/**
* Return the current element as a CollectionInfo instance.
*
......@@ -41,6 +55,12 @@ class CollectionInfoCommandIterator extends IteratorIterator implements Collecti
*/
public function current()
{
return new CollectionInfo(parent::current());
$info = parent::current();
if ($this->databaseName !== null && isset($info['idIndex']) && ! isset($info['idIndex']['ns'])) {
$info['idIndex']['ns'] = $this->databaseName . '.' . $info['name'];
}
return new CollectionInfo($info);
}
}
......@@ -136,6 +136,6 @@ class ListCollections implements Executable
$cursor = $server->executeReadCommand($this->databaseName, new Command($cmd), $this->createOptions());
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
return new CollectionInfoCommandIterator(new CachingIterator($cursor));
return new CollectionInfoCommandIterator(new CachingIterator($cursor), $this->databaseName);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment