Commit d1883777 authored by Jens Segers's avatar Jens Segers

Merge pull request #406 from bonroyage/master

Added cursor hint
parents e6ad623f 7b02af30
...@@ -29,6 +29,13 @@ class Builder extends BaseBuilder { ...@@ -29,6 +29,13 @@ class Builder extends BaseBuilder {
*/ */
public $timeout; public $timeout;
/**
* The cursor hint value.
*
* @var int
*/
public $hint;
/** /**
* Indicate if we are executing a pagination query. * Indicate if we are executing a pagination query.
* *
...@@ -104,6 +111,19 @@ class Builder extends BaseBuilder { ...@@ -104,6 +111,19 @@ class Builder extends BaseBuilder {
return $this; return $this;
} }
/**
* Set the cursor hint.
*
* @param mixed $index
* @return $this
*/
public function hint($index)
{
$this->hint = $index;
return $this;
}
/** /**
* Execute a query for a single record by ID. * Execute a query for a single record by ID.
* *
...@@ -266,11 +286,12 @@ class Builder extends BaseBuilder { ...@@ -266,11 +286,12 @@ class Builder extends BaseBuilder {
// Execute query and get MongoCursor // Execute query and get MongoCursor
$cursor = $this->collection->find($wheres, $columns); $cursor = $this->collection->find($wheres, $columns);
// Apply order, offset and limit // Apply order, offset, limit and hint
if ($this->timeout) $cursor->timeout($this->timeout); if ($this->timeout) $cursor->timeout($this->timeout);
if ($this->orders) $cursor->sort($this->orders); if ($this->orders) $cursor->sort($this->orders);
if ($this->offset) $cursor->skip($this->offset); if ($this->offset) $cursor->skip($this->offset);
if ($this->limit) $cursor->limit($this->limit); if ($this->limit) $cursor->limit($this->limit);
if ($this->hint) $cursor->hint($this->hint);
// Return results as an array with numeric keys // Return results as an array with numeric keys
return iterator_to_array($cursor, false); return iterator_to_array($cursor, false);
......
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