Commit ea9a7ced authored by Jens Segers's avatar Jens Segers

Adding cursor timeout, fixes #252

parent ea5299d9
...@@ -557,6 +557,12 @@ The MongoClient and MongoDB objects can be accessed like this: ...@@ -557,6 +557,12 @@ The MongoClient and MongoDB objects can be accessed like this:
### MongoDB specific operations ### MongoDB specific operations
**Cursor timeout**
To prevent MongoCursorTimeout exceptions, you can manually set a timeout value that will be applied to the cursor:
DB::collection('users')->timeout(-1)->get();
**Upsert** **Upsert**
Update or insert a document. Additional options for the update method are passed directly to the native update method. Update or insert a document. Additional options for the update method are passed directly to the native update method.
......
...@@ -25,6 +25,13 @@ class Builder extends \Illuminate\Database\Query\Builder { ...@@ -25,6 +25,13 @@ class Builder extends \Illuminate\Database\Query\Builder {
*/ */
public $projections; public $projections;
/**
* The cursor timeout value.
*
* @var int
*/
public $timeout;
/** /**
* All of the available clause operators. * All of the available clause operators.
* *
...@@ -79,6 +86,19 @@ class Builder extends \Illuminate\Database\Query\Builder { ...@@ -79,6 +86,19 @@ class Builder extends \Illuminate\Database\Query\Builder {
return $this; return $this;
} }
/**
* Set the cursor timeout in seconds.
*
* @param int $seconds
* @return $this
*/
public function timeout($seconds)
{
$this->timeout = $seconds;
return $this;
}
/** /**
* Execute a query for a single record by ID. * Execute a query for a single record by ID.
* *
...@@ -217,9 +237,10 @@ class Builder extends \Illuminate\Database\Query\Builder { ...@@ -217,9 +237,10 @@ class Builder extends \Illuminate\Database\Query\Builder {
$cursor = $this->collection->find($wheres, $columns); $cursor = $this->collection->find($wheres, $columns);
// Apply order, offset and limit // Apply order, offset and limit
if ($this->orders) $cursor->sort($this->orders); if ($this->timeout) $cursor->timeout($this->timeout);
if ($this->offset) $cursor->skip($this->offset); if ($this->orders) $cursor->sort($this->orders);
if ($this->limit) $cursor->limit($this->limit); if ($this->offset) $cursor->skip($this->offset);
if ($this->limit) $cursor->limit($this->limit);
// 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