Skip to content

Commit

Permalink
Include option to disable mongo cursor timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
gmsantos committed Aug 2, 2016
1 parent 84d52ac commit 39d30d1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Mongolid/Cursor/Cursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,21 @@ public function skip(int $amount)
return $this;
}

/**
* Disable idle timeout of 10 minutes from MongoDB cursor.
* This method should be called before the cursor was started.
*
* @param boolean $flag Toggle timeout on or off.
*
* @return Cursor Returns this cursor.
*/
public function disableTimeout(bool $flag = true)
{
$this->params[1]['noCursorTimeout'] = $flag;

return $this;
}

/**
* Counts the number of results for this cursor
*
Expand Down Expand Up @@ -225,7 +240,7 @@ public function first()

/**
* Refresh the cursor in order to be able to perform a rewind and iterate
* trought it again. A new request to the database will be made in the next
* through it again. A new request to the database will be made in the next
* iteration.
*
* @return void
Expand Down
14 changes: 14 additions & 0 deletions tests/Mongolid/Cursor/CursorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ public function testShouldSkipDocuments()
);
}

public function testShouldSetNoCursorTimeoutToTrue()
{
// Arrange
$cursor = $this->getCursor();

// Assert
$cursor->disableTimeout();
$this->assertAttributeEquals(
[[], ['noCursorTimeout' => true]],
'params',
$cursor
);
}

public function testShouldCountDocuments()
{
// Arrange
Expand Down

0 comments on commit 39d30d1

Please sign in to comment.