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
0f2520f2
Commit
0f2520f2
authored
Sep 28, 2016
by
Ryan Hayle
Committed by
Jens Segers
Sep 28, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow setting custom options on a query [Fixes #541] (#959)
parent
ca4914cc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
Builder.php
src/Jenssegers/Mongodb/Query/Builder.php
+30
-0
No files found.
src/Jenssegers/Mongodb/Query/Builder.php
View file @
0f2520f2
...
@@ -41,6 +41,13 @@ class Builder extends BaseBuilder
...
@@ -41,6 +41,13 @@ class Builder extends BaseBuilder
*/
*/
public
$hint
;
public
$hint
;
/**
* Custom options to add to the query.
*
* @var array
*/
public
$options
=
[];
/**
/**
* Indicate if we are executing a pagination query.
* Indicate if we are executing a pagination query.
*
*
...
@@ -263,6 +270,11 @@ class Builder extends BaseBuilder
...
@@ -263,6 +270,11 @@ class Builder extends BaseBuilder
'typeMap'
=>
[
'root'
=>
'array'
,
'document'
=>
'array'
],
'typeMap'
=>
[
'root'
=>
'array'
,
'document'
=>
'array'
],
];
];
// Add custom query options
if
(
count
(
$this
->
options
))
{
$options
=
array_merge
(
$options
,
$this
->
options
);
}
// Execute aggregation
// Execute aggregation
$results
=
iterator_to_array
(
$this
->
collection
->
aggregate
(
$pipeline
,
$options
));
$results
=
iterator_to_array
(
$this
->
collection
->
aggregate
(
$pipeline
,
$options
));
...
@@ -321,6 +333,11 @@ class Builder extends BaseBuilder
...
@@ -321,6 +333,11 @@ class Builder extends BaseBuilder
// Fix for legacy support, converts the results to arrays instead of objects.
// Fix for legacy support, converts the results to arrays instead of objects.
$options
[
'typeMap'
]
=
[
'root'
=>
'array'
,
'document'
=>
'array'
];
$options
[
'typeMap'
]
=
[
'root'
=>
'array'
,
'document'
=>
'array'
];
// Add custom query options
if
(
count
(
$this
->
options
))
{
$options
=
array_merge
(
$options
,
$this
->
options
);
}
// Execute query and get MongoCursor
// Execute query and get MongoCursor
$cursor
=
$this
->
collection
->
find
(
$wheres
,
$options
);
$cursor
=
$this
->
collection
->
find
(
$wheres
,
$options
);
...
@@ -1019,6 +1036,19 @@ class Builder extends BaseBuilder
...
@@ -1019,6 +1036,19 @@ class Builder extends BaseBuilder
return
$where
[
'sql'
];
return
$where
[
'sql'
];
}
}
/**
* Set custom options for the query.
*
* @param array $options
* @return $this
*/
public
function
options
(
array
$options
)
{
$this
->
options
=
$options
;
return
$this
;
}
/**
/**
* Handle dynamic method calls into the method.
* Handle dynamic method calls into the method.
*
*
...
...
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