Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
laravel-mongodb
Commits
ea9a7ced
Commit
ea9a7ced
authored
Aug 09, 2014
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding cursor timeout, fixes #252
parent
ea5299d9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
3 deletions
+30
-3
README.md
README.md
+6
-0
Builder.php
src/Jenssegers/Mongodb/Query/Builder.php
+24
-3
No files found.
README.md
View file @
ea9a7ced
...
@@ -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.
...
...
src/Jenssegers/Mongodb/Query/Builder.php
View file @
ea9a7ced
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment