Commit a995a887 authored by Hannes Magnusson's avatar Hannes Magnusson

Improve Command Cursor suport

parent eaaf42b5
......@@ -62,9 +62,12 @@ try {
echo "Distinct countries:\n";
var_dump($result);
$aggregate = $collection->aggregate(array(array('$project' => array("name" => 1, "_id" => 0))), array("useCursor" => false));
echo "aggregate\n";
$aggregate = $collection->aggregate(array(array('$project' => array("name" => 1, "_id" => 0))), array("useCursor" => true, "batchSize" => 2));
printf("Should be 3 different people\n");
var_dump($aggregate);
foreach($aggregate as $person) {
var_dump($person);
}
$result = $collection->updateMany(
array("citizen" => "Iceland"),
......
......@@ -296,10 +296,16 @@ class Collection {
"pipeline" => $pipeline,
) + $options;
$doc = $this->_runCommand($this->dbname, $cmd)->getResponseDocument();
if ($doc["ok"]) {
return $doc["result"];
$result = $this->_runCommand($this->dbname, $cmd);
$doc = $result->getResponseDocument();
if (isset($cmd["cursor"]) && $cmd["cursor"]) {
return $result;
} else {
if ($doc["ok"]) {
return new \ArrayIterator($doc["result"]);
}
}
throw $this->_generateCommandException($doc);
} /* }}} */
function getAggregateOptions() { /* {{{ */
......@@ -358,7 +364,7 @@ class Collection {
return new Exception($doc["errmsg"]);
}
var_dump($doc);
return new Exception("FIXME: Unknown error");
return new \Exception("FIXME: Unknown error");
} /* }}} */
protected function _runCommand($dbname, array $cmd, ReadPreference $rp = null) { /* {{{ */
//var_dump(\BSON\toJSON(\BSON\fromArray($cmd)));
......
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