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
12 years ago
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tweaks
parent
1b815c83
master
2.0
2.1
2.2
2.3
4.2
develop
4.0.0-alpha.1
v3.6.4
v3.6.3
v3.6.2
v3.6.1
v3.6.0
v3.5.3
v3.5.2
v3.5.1
v3.5.0
v3.4.6
v3.4.5
v3.4.4
v3.4.3
v3.4.2
v3.4.1
v3.4.0
v3.3.1
v3.3.0
v3.3.0-alpha
v3.2.3
v3.2.2
v3.2.1
v3.2.0
v3.1.4
v3.1.3
v3.1.2
v3.1.1
v3.1.0
v3.1.0-alpha
v3.0.2
v3.0.1
v3.0.0
v3.0.0-beta
v3.0.0-alpha
v2.3.5
v2.3.4
v2.3.3
v2.3.2
v2.3.1
v2.3.0
v2.2.10
v2.2.9
v2.2.8
v2.2.7
v2.2.6
v2.2.5
v2.2.4
v2.2.3
v2.2.2
v2.2.1
v2.2.0
v2.1.9
v2.1.8
v2.1.7
v2.1.6
v2.1.5
v2.1.4
v2.1.3
v2.1.2
v2.1.1
v2.1.0
v2.1.0-beta
v2.0.5
v2.0.4
v2.0.3
v2.0.2
v2.0.1
v2.0.0
v2.0.0-alpha
v1.4.3
v1.4.2
v1.4.1
v1.4.0
v1.3.2
v1.3.1
v1.3.0
v1.2.9
v1.2.8
v1.2.7
v1.2.6
v1.2.5
v1.2.4
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.1.4
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.8
v1.0.7
v1.0.6
v1.0.5
v1.0.4
v1.0.3
v1.0.2
v1.0.1
v1.0.0
No related merge requests found
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 {
}
// 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
)
{
// We can only return an array of distinct values for a single column
return
$this
->
collection
->
distinct
(
$this
->
distinct
,
$this
->
compileWheres
());
}
else
if
(
count
(
$this
->
groups
))
{
// We can pass our wheres as a condition
$options
=
array
();
$options
[
'condition'
]
=
$this
->
compileWheres
();
$keys
=
array
();
foreach
(
$this
->
groups
as
$group
)
$keys
[
$group
]
=
1
;
// Initial value and reduce code
$initial
=
array
(
"item"
=>
""
);
$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'
];
// Transform results to a nice array
$results
=
array
();
foreach
(
$items
as
$item
)
{
$results
[]
=
$item
[
'item'
];
}
// Return these results since we don't have a MongoCursor
return
$results
;
}
else
{
// Get the MongoCursor
$cursor
=
$this
->
collection
->
find
(
$this
->
compileWheres
(),
$this
->
columns
);
}
...
...
@@ -119,6 +127,7 @@ class Query extends \Illuminate\Database\Query\Builder {
$cursor
->
limit
(
$this
->
limit
);
}
// Return results
return
$cursor
;
}
...
...
@@ -136,6 +145,24 @@ class Query extends \Illuminate\Database\Query\Builder {
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.
*
...
...
@@ -212,7 +239,9 @@ class Query extends \Illuminate\Database\Query\Builder {
public
function
from
(
$collection
)
{
if
(
$collection
)
{
$this
->
collection
=
$this
->
connection
->
getCollection
(
$collection
);
}
return
$this
;
}
...
...
This diff is collapsed.
Click to expand it.
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