Skip to content

Commit 7b02af3

Browse files
committed
Added cursor hint
1 parent 23f93ae commit 7b02af3

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
@@ -32,6 +32,13 @@ class Builder extends QueryBuilder {
3232
* @var int
3333
*/
3434
public $timeout;
35+
36+
/**
37+
* The cursor hint value.
38+
*
39+
* @var int
40+
*/
41+
public $hint;
3542

3643
/**
3744
* All of the available clause operators.
@@ -99,6 +106,19 @@ public function timeout($seconds)
99106

100107
return $this;
101108
}
109+
110+
/**
111+
* Set the cursor hint.
112+
*
113+
* @param mixed $index
114+
* @return $this
115+
*/
116+
public function hint($index)
117+
{
118+
$this->hint = $index;
119+
120+
return $this;
121+
}
102122

103123
/**
104124
* Execute a query for a single record by ID.
@@ -249,11 +269,12 @@ public function getFresh($columns = array())
249269
// Execute query and get MongoCursor
250270
$cursor = $this->collection->find($wheres, $columns);
251271

252-
// Apply order, offset and limit
272+
// Apply order, offset, limit and hint
253273
if ($this->timeout) $cursor->timeout($this->timeout);
254274
if ($this->orders) $cursor->sort($this->orders);
255275
if ($this->offset) $cursor->skip($this->offset);
256276
if ($this->limit) $cursor->limit($this->limit);
277+
if ($this->hint) $cursor->hint($this->hint);
257278

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

0 commit comments

Comments
 (0)