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
43230579
Commit
43230579
authored
May 01, 2013
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added like regexp
parent
d50a4b4b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
4 deletions
+33
-4
README.md
README.md
+7
-0
Query.php
src/Jenssegers/Mongodb/Query.php
+26
-4
No files found.
README.md
View file @
43230579
...
...
@@ -91,6 +91,8 @@ Examples
**Group By**
Selected columns that are not grouped will be aggregated with the $last function.
$users = Users::groupBy('title')->get(array('title', 'name'));
**Aggregation**
...
...
@@ -99,5 +101,10 @@ Examples
$price = Order::min('price');
$price = Order::avg('price');
$total = User::sum('votes');
$total = Order::count();
**Like**
$user = Comment::where('body', 'like', '%spam%')->get();
All basic insert, update, delete and select methods should be implemented. Feel free to fork and help completing this library!
\ No newline at end of file
src/Jenssegers/Mongodb/Query.php
View file @
43230579
<?php
namespace
Jenssegers\Mongodb
;
use
MongoID
;
use
MongoRegex
;
class
Query
extends
\Illuminate\Database\Query\Builder
{
...
...
@@ -79,7 +80,7 @@ class Query extends \Illuminate\Database\Query\Builder {
{
$pipeline
=
array
();
// Group
// Group
ing
$group
=
array
();
$group
[
'_id'
]
=
$this
->
groups
?
$this
->
groups
:
0
;
...
...
@@ -92,9 +93,17 @@ class Query extends \Illuminate\Database\Query\Builder {
// Apply aggregation functions
if
(
$this
->
aggregate
)
{
$function
=
$this
->
aggregate
[
'function'
];
foreach
(
$this
->
aggregate
[
'columns'
]
as
$column
)
{
$group
[
$column
]
=
array
(
'$'
.
$this
->
aggregate
[
'function'
]
=>
'$'
.
$column
);
if
(
$function
==
'count'
)
{
$group
[
$column
]
=
array
(
'$sum'
=>
1
);
}
else
{
$group
[
$column
]
=
array
(
'$'
.
$function
=>
'$'
.
$column
);
}
}
}
...
...
@@ -150,7 +159,7 @@ class Query extends \Illuminate\Database\Query\Builder {
*
* @param string $column
* @param string $direction
* @return
\Illuminate\Database\Query\
Builder
* @return Builder
*/
public
function
orderBy
(
$column
,
$direction
=
'asc'
)
{
...
...
@@ -163,7 +172,7 @@ class Query extends \Illuminate\Database\Query\Builder {
* Add a "group by" clause to the query.
*
* @param dynamic $columns
* @return
\Illuminate\Database\Query\
Builder
* @return Builder
*/
public
function
groupBy
()
{
...
...
@@ -312,6 +321,19 @@ class Query extends \Illuminate\Database\Query\Builder {
{
extract
(
$where
);
// Replace like with MongoRegex
if
(
$operator
==
'like'
)
{
$operator
=
'='
;
$regex
=
str_replace
(
'%'
,
''
,
$value
);
// Prepare regex
if
(
substr
(
$value
,
0
,
1
)
!=
'%'
)
$regex
=
'^'
.
$regex
;
if
(
substr
(
$value
,
-
1
)
!=
'%'
)
$regex
=
$regex
.
'$'
;
$value
=
new
MongoRegex
(
"/
$regex
/i"
);
}
if
(
!
isset
(
$operator
)
||
$operator
==
'='
)
{
$query
=
array
(
$column
=>
$value
);
...
...
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