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
2c95ab73
Commit
2c95ab73
authored
Jan 31, 2020
by
Ditty
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow setting hint option on querybuilder
Co-Authored-By:
Manan Jadhav
<
jadhavm@uwindsor.ca
>
parent
c25900b3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
1 deletion
+24
-1
Builder.php
src/Jenssegers/Mongodb/Query/Builder.php
+3
-1
QueryBuilderTest.php
tests/QueryBuilderTest.php
+21
-0
No files found.
src/Jenssegers/Mongodb/Query/Builder.php
View file @
2c95ab73
...
...
@@ -384,10 +384,12 @@ class Builder extends BaseBuilder
if
(
$this
->
limit
)
{
$options
[
'limit'
]
=
$this
->
limit
;
}
if
(
$this
->
hint
)
{
$options
[
'hint'
]
=
$this
->
hint
;
}
if
(
$columns
)
{
$options
[
'projection'
]
=
$columns
;
}
// if ($this->hint) $cursor->hint($this->hint);
// Fix for legacy support, converts the results to arrays instead of objects.
$options
[
'typeMap'
]
=
[
'root'
=>
'array'
,
'document'
=>
'array'
];
...
...
tests/QueryBuilderTest.php
View file @
2c95ab73
...
...
@@ -737,4 +737,25 @@ class QueryBuilderTest extends TestCase
$this
->
assertEquals
(
'Herman'
,
DB
::
collection
(
'books'
)
->
value
(
'author.first_name'
));
$this
->
assertEquals
(
'Melville'
,
DB
::
collection
(
'books'
)
->
value
(
'author.last_name'
));
}
public
function
testHintOptions
()
{
DB
::
collection
(
'items'
)
->
insert
([
[
'name'
=>
'fork'
,
'tags'
=>
[
'sharp'
,
'pointy'
]],
[
'name'
=>
'spork'
,
'tags'
=>
[
'sharp'
,
'pointy'
,
'round'
,
'bowl'
]],
[
'name'
=>
'spoon'
,
'tags'
=>
[
'round'
,
'bowl'
]],
]);
$results
=
DB
::
collection
(
'items'
)
->
hint
([
'$natural'
=>
-
1
])
->
get
();
$this
->
assertArraySubset
([
'name'
=>
'spoon'
],
$results
[
0
]);
$this
->
assertArraySubset
([
'name'
=>
'spork'
],
$results
[
1
]);
$this
->
assertArraySubset
([
'name'
=>
'fork'
],
$results
[
2
]);
$results
=
DB
::
collection
(
'items'
)
->
hint
([
'$natural'
=>
1
])
->
get
();
$this
->
assertArraySubset
([
'name'
=>
'spoon'
],
$results
[
2
]);
$this
->
assertArraySubset
([
'name'
=>
'spork'
],
$results
[
1
]);
$this
->
assertArraySubset
([
'name'
=>
'fork'
],
$results
[
0
]);
}
}
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