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
fcf5465f
Commit
fcf5465f
authored
May 01, 2013
by
Jens Segers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding distinct
parent
7e14145d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
0 deletions
+33
-0
README.md
README.md
+9
-0
Query.php
src/Jenssegers/Mongodb/Query.php
+24
-0
No files found.
README.md
View file @
fcf5465f
...
@@ -88,6 +88,15 @@ Examples
...
@@ -88,6 +88,15 @@ Examples
$users = User::skip(10)->take(5)->get();
$users = User::skip(10)->take(5)->get();
**Distinct**
Distinct requires a field for which to return the distinct values.
$users = User::distinct()->get(array('name'));
// or
$users = User::distinct('name')->get();
**Advanced Wheres**
**Advanced Wheres**
$users = User::where('name', '=', 'John')->orWhere(function($query)
$users = User::where('name', '=', 'John')->orWhere(function($query)
...
...
src/Jenssegers/Mongodb/Query.php
View file @
fcf5465f
...
@@ -122,6 +122,13 @@ class Query extends \Illuminate\Database\Query\Builder {
...
@@ -122,6 +122,13 @@ class Query extends \Illuminate\Database\Query\Builder {
}
}
else
else
{
{
// Execute distinct
if
(
$this
->
distinct
)
{
$column
=
isset
(
$this
->
columns
[
0
])
?
$this
->
columns
[
0
]
:
'_id'
;
return
$this
->
collection
->
distinct
(
$column
,
$wheres
);
}
// Get the MongoCursor
// Get the MongoCursor
$cursor
=
$this
->
collection
->
find
(
$wheres
,
$this
->
columns
);
$cursor
=
$this
->
collection
->
find
(
$wheres
,
$this
->
columns
);
...
@@ -154,6 +161,23 @@ class Query extends \Illuminate\Database\Query\Builder {
...
@@ -154,6 +161,23 @@ class Query extends \Illuminate\Database\Query\Builder {
}
}
}
}
/**
* Force the query to only return distinct results.
*
* @return \Illuminate\Database\Query\Builder
*/
public
function
distinct
(
$column
=
false
)
{
$this
->
distinct
=
true
;
if
(
$column
)
{
$this
->
columns
=
array
(
$column
);
}
return
$this
;
}
/**
/**
* Add an "order by" clause to the query.
* Add an "order by" clause to the query.
*
*
...
...
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