Skip to content

Commit d188377

Browse files
committed
Merge pull request #406 from bonroyage/master
Added cursor hint
2 parents e6ad623 + 7b02af3 commit d188377

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/Jenssegers/Mongodb/Query/Builder.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ class Builder extends BaseBuilder {
2828
* @var int
2929
*/
3030
public $timeout;
31+
32+
/**
33+
* The cursor hint value.
34+
*
35+
* @var int
36+
*/
37+
public $hint;
3138

3239
/**
3340
* Indicate if we are executing a pagination query.
@@ -103,6 +110,19 @@ public function timeout($seconds)
103110

104111
return $this;
105112
}
113+
114+
/**
115+
* Set the cursor hint.
116+
*
117+
* @param mixed $index
118+
* @return $this
119+
*/
120+
public function hint($index)
121+
{
122+
$this->hint = $index;
123+
124+
return $this;
125+
}
106126

107127
/**
108128
* Execute a query for a single record by ID.
@@ -266,11 +286,12 @@ public function getFresh($columns = array())
266286
// Execute query and get MongoCursor
267287
$cursor = $this->collection->find($wheres, $columns);
268288

269-
// Apply order, offset and limit
289+
// Apply order, offset, limit and hint
270290
if ($this->timeout) $cursor->timeout($this->timeout);
271291
if ($this->orders) $cursor->sort($this->orders);
272292
if ($this->offset) $cursor->skip($this->offset);
273293
if ($this->limit) $cursor->limit($this->limit);
294+
if ($this->hint) $cursor->hint($this->hint);
274295

275296
// Return results as an array with numeric keys
276297
return iterator_to_array($cursor, false);

0 commit comments

Comments
 (0)