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
25a8bacf
Commit
25a8bacf
authored
Apr 28, 2014
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add elemMatch operator
parent
d78e126c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
1 deletion
+28
-1
Builder.php
src/Jenssegers/Mongodb/Query/Builder.php
+7
-1
QueryBuilderTest.php
tests/QueryBuilderTest.php
+21
-0
No files found.
src/Jenssegers/Mongodb/Query/Builder.php
View file @
25a8bacf
...
...
@@ -27,7 +27,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
'='
,
'<'
,
'>'
,
'<='
,
'>='
,
'<>'
,
'!='
,
'like'
,
'not like'
,
'between'
,
'ilike'
,
'&'
,
'|'
,
'^'
,
'<<'
,
'>>'
,
'exists'
,
'type'
,
'mod'
,
'where'
,
'all'
,
'size'
,
'regex'
,
'exists'
,
'type'
,
'mod'
,
'where'
,
'all'
,
'size'
,
'regex'
,
'elemmatch'
);
/**
...
...
@@ -678,6 +678,12 @@ class Builder extends \Illuminate\Database\Query\Builder {
if
(
isset
(
$where
[
'operator'
]))
{
$where
[
'operator'
]
=
strtolower
(
$where
[
'operator'
]);
// Fix elemMatch
if
(
$where
[
'operator'
]
==
'elemmatch'
)
{
$where
[
'operator'
]
=
'elemMatch'
;
}
}
// Convert id's
...
...
tests/QueryBuilderTest.php
View file @
25a8bacf
...
...
@@ -532,6 +532,27 @@ class QueryBuilderTest extends TestCase {
$results
=
DB
::
collection
(
'users'
)
->
where
(
'name'
,
'REGEX'
,
$regex
)
->
get
();
$this
->
assertEquals
(
2
,
count
(
$results
));
DB
::
collection
(
'users'
)
->
insert
(
array
(
array
(
'name'
=>
'John Doe'
,
'addresses'
=>
array
(
array
(
'city'
=>
'Ghent'
),
array
(
'city'
=>
'Paris'
)
)
),
array
(
'name'
=>
'Jane Doe'
,
'addresses'
=>
array
(
array
(
'city'
=>
'Brussels'
),
array
(
'city'
=>
'Paris'
)
)
)
));
$users
=
DB
::
collection
(
'users'
)
->
where
(
'addresses'
,
'elemMatch'
,
array
(
'city'
=>
'Brussels'
))
->
get
();
$this
->
assertEquals
(
1
,
count
(
$users
));
$this
->
assertEquals
(
'Jane Doe'
,
$users
[
0
][
'name'
]);
}
public
function
testIncrement
()
...
...
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