Commit a995a887 authored by Hannes Magnusson's avatar Hannes Magnusson

Improve Command Cursor suport

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