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
6df8a487
Commit
6df8a487
authored
Jun 11, 2014
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding more mongodb operators
parent
162869b3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
8 deletions
+26
-8
Builder.php
src/Jenssegers/Mongodb/Query/Builder.php
+22
-8
QueryBuilderTest.php
tests/QueryBuilderTest.php
+4
-0
No files found.
src/Jenssegers/Mongodb/Query/Builder.php
View file @
6df8a487
...
...
@@ -27,7 +27,10 @@ class Builder extends \Illuminate\Database\Query\Builder {
'='
,
'<'
,
'>'
,
'<='
,
'>='
,
'<>'
,
'!='
,
'like'
,
'not like'
,
'between'
,
'ilike'
,
'&'
,
'|'
,
'^'
,
'<<'
,
'>>'
,
'exists'
,
'type'
,
'mod'
,
'where'
,
'all'
,
'size'
,
'regex'
,
'elemmatch'
'rlike'
,
'regexp'
,
'not regexp'
,
'exists'
,
'type'
,
'mod'
,
'where'
,
'all'
,
'size'
,
'regex'
,
'text'
,
'slice'
,
'elemmatch'
,
'geowithin'
,
'geointersects'
,
'near'
,
'nearsphere'
,
'geometry'
,
'maxdistance'
,
'center'
,
'centersphere'
,
'box'
,
'polygon'
,
'uniquedocs'
,
);
/**
...
...
@@ -90,7 +93,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
$wheres
=
$this
->
compileWheres
();
// Use MongoDB's aggregation framework when using grouping or aggregation functions.
if
(
$this
->
groups
||
$this
->
aggregate
)
if
(
$this
->
groups
or
$this
->
aggregate
)
{
$group
=
array
();
...
...
@@ -652,7 +655,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
*/
public
function
convertKey
(
$id
)
{
if
(
is_string
(
$id
)
&&
strlen
(
$id
)
===
24
&&
ctype_xdigit
(
$id
))
if
(
is_string
(
$id
)
and
strlen
(
$id
)
===
24
and
ctype_xdigit
(
$id
))
{
return
new
MongoId
(
$id
);
}
...
...
@@ -680,15 +683,26 @@ class Builder extends \Illuminate\Database\Query\Builder {
{
$where
[
'operator'
]
=
strtolower
(
$where
[
'operator'
]);
// Fix elemMatch.
if
(
$where
[
'operator'
]
==
'elemmatch'
)
// Operator conversions
$convert
=
array
(
'regexp'
=>
'regex'
,
'elemmatch'
=>
'elemMatch'
,
'geointersects'
=>
'geoIntersects'
,
'geowithin'
=>
'geoWithin'
,
'nearsphere'
=>
'nearSphere'
,
'maxdistance'
=>
'maxDistance'
,
'centersphere'
=>
'centerSphere'
,
'uniquedocs'
=>
'uniqueDocs'
,
);
if
(
array_key_exists
(
$where
[
'operator'
],
$convert
))
{
$where
[
'operator'
]
=
'elemMatch'
;
$where
[
'operator'
]
=
$convert
[
$where
[
'operator'
]]
;
}
}
// Convert id's.
if
(
isset
(
$where
[
'column'
])
&&
$where
[
'column'
]
==
'_id'
)
if
(
isset
(
$where
[
'column'
])
and
$where
[
'column'
]
==
'_id'
)
{
// Multiple values.
if
(
isset
(
$where
[
'values'
]))
...
...
@@ -707,7 +721,7 @@ class Builder extends \Illuminate\Database\Query\Builder {
}
// Convert DateTime values to MongoDate.
if
(
isset
(
$where
[
'value'
])
&&
$where
[
'value'
]
instanceof
DateTime
)
if
(
isset
(
$where
[
'value'
])
and
$where
[
'value'
]
instanceof
DateTime
)
{
$where
[
'value'
]
=
new
MongoDate
(
$where
[
'value'
]
->
getTimestamp
());
}
...
...
tests/QueryBuilderTest.php
View file @
6df8a487
...
...
@@ -530,6 +530,10 @@ class QueryBuilderTest extends TestCase {
$results
=
DB
::
collection
(
'users'
)
->
where
(
'name'
,
'regex'
,
$regex
)
->
get
();
$this
->
assertEquals
(
2
,
count
(
$results
));
$regex
=
new
MongoRegex
(
"/.*doe/i"
);
$results
=
DB
::
collection
(
'users'
)
->
where
(
'name'
,
'regexp'
,
$regex
)
->
get
();
$this
->
assertEquals
(
2
,
count
(
$results
));
$results
=
DB
::
collection
(
'users'
)
->
where
(
'name'
,
'REGEX'
,
$regex
)
->
get
();
$this
->
assertEquals
(
2
,
count
(
$results
));
...
...
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