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
5fe429d5
Commit
5fe429d5
authored
Apr 28, 2013
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tweaks
parent
1b815c83
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
7 deletions
+36
-7
Query.php
src/Jenssegers/Mongodb/Query.php
+36
-7
No files found.
src/Jenssegers/Mongodb/Query.php
View file @
5fe429d5
...
@@ -68,36 +68,44 @@ class Query extends \Illuminate\Database\Query\Builder {
...
@@ -68,36 +68,44 @@ class Query extends \Illuminate\Database\Query\Builder {
}
}
// Drop all columns if * is present
// Drop all columns if * is present
if
(
in_array
(
'*'
,
$this
->
columns
))
$this
->
columns
=
array
();
if
(
in_array
(
'*'
,
$this
->
columns
))
{
$this
->
columns
=
array
();
}
// Get Mongo cursor
if
(
$this
->
distinct
)
if
(
$this
->
distinct
)
{
{
// We can only return an array of distinct values for a single column
return
$this
->
collection
->
distinct
(
$this
->
distinct
,
$this
->
compileWheres
());
return
$this
->
collection
->
distinct
(
$this
->
distinct
,
$this
->
compileWheres
());
}
}
else
if
(
count
(
$this
->
groups
))
else
if
(
count
(
$this
->
groups
))
{
{
// We can pass our wheres as a condition
$options
=
array
();
$options
=
array
();
$options
[
'condition'
]
=
$this
->
compileWheres
();
$options
[
'condition'
]
=
$this
->
compileWheres
();
$keys
=
array
();
// Initial value and reduce code
foreach
(
$this
->
groups
as
$group
)
$keys
[
$group
]
=
1
;
$initial
=
array
(
"item"
=>
""
);
$initial
=
array
(
"item"
=>
""
);
$reduce
=
"function (obj, prev) { prev.item = obj; }"
;
$reduce
=
"function (obj, prev) { prev.item = obj; }"
;
$result
=
$this
->
collection
->
group
(
$keys
,
$initial
,
$reduce
,
$options
);
// Get results
$result
=
$this
->
collection
->
group
(
$this
->
groups
,
$initial
,
$reduce
,
$options
);
$items
=
$result
[
'retval'
];
$items
=
$result
[
'retval'
];
// Transform results to a nice array
$results
=
array
();
$results
=
array
();
foreach
(
$items
as
$item
)
foreach
(
$items
as
$item
)
{
$results
[]
=
$item
[
'item'
];
$results
[]
=
$item
[
'item'
];
}
// Return these results since we don't have a MongoCursor
return
$results
;
return
$results
;
}
}
else
else
{
{
// Get the MongoCursor
$cursor
=
$this
->
collection
->
find
(
$this
->
compileWheres
(),
$this
->
columns
);
$cursor
=
$this
->
collection
->
find
(
$this
->
compileWheres
(),
$this
->
columns
);
}
}
...
@@ -119,6 +127,7 @@ class Query extends \Illuminate\Database\Query\Builder {
...
@@ -119,6 +127,7 @@ class Query extends \Illuminate\Database\Query\Builder {
$cursor
->
limit
(
$this
->
limit
);
$cursor
->
limit
(
$this
->
limit
);
}
}
// Return results
return
$cursor
;
return
$cursor
;
}
}
...
@@ -136,6 +145,24 @@ class Query extends \Illuminate\Database\Query\Builder {
...
@@ -136,6 +145,24 @@ class Query extends \Illuminate\Database\Query\Builder {
return
$this
;
return
$this
;
}
}
/**
* Add a "group by" clause to the query.
*
* @param dynamic $columns
* @return \Illuminate\Database\Query\Builder
*/
public
function
groupBy
()
{
$groups
=
func_get_args
();
foreach
(
$groups
as
$group
)
{
$this
->
groups
[
$group
]
=
1
;
}
return
$this
;
}
/**
/**
* Insert a new record into the database.
* Insert a new record into the database.
*
*
...
@@ -212,7 +239,9 @@ class Query extends \Illuminate\Database\Query\Builder {
...
@@ -212,7 +239,9 @@ class Query extends \Illuminate\Database\Query\Builder {
public
function
from
(
$collection
)
public
function
from
(
$collection
)
{
{
if
(
$collection
)
if
(
$collection
)
{
$this
->
collection
=
$this
->
connection
->
getCollection
(
$collection
);
$this
->
collection
=
$this
->
connection
->
getCollection
(
$collection
);
}
return
$this
;
return
$this
;
}
}
...
...
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