Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
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
mongo-php-library
Commits
de032a57
Commit
de032a57
authored
Dec 05, 2014
by
Hannes Magnusson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHP-1303: Collection::distinct()
parent
865685e1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
0 deletions
+29
-0
write.php
examples/write.php
+3
-0
Collection.php
src/MongoDB/Collection.php
+26
-0
No files found.
examples/write.php
View file @
de032a57
...
...
@@ -58,6 +58,9 @@ try {
foreach
(
$result
as
$document
)
{
var_dump
(
$document
);
}
$result
=
$collection
->
distinct
(
"citizen"
);
echo
"Distinct countries:
\n
"
;
var_dump
(
$result
);
$result
=
$collection
->
updateMany
(
array
(
"citizen"
=>
"Iceland"
),
...
...
src/MongoDB/Collection.php
View file @
de032a57
...
...
@@ -264,6 +264,32 @@ class Collection {
);
}
/* }}} */
function
distinct
(
$fieldName
,
array
$filter
=
array
(),
array
$options
=
array
())
{
/* {{{ */
$options
=
array_merge
(
$this
->
getFindOptions
(),
$options
);
$cmd
=
array
(
"distinct"
=>
$this
->
collname
,
"key"
=>
$fieldName
,
"query"
=>
$filter
,
$options
);
$doc
=
$this
->
_runCommand
(
$this
->
dbname
,
$cmd
)
->
getResponseDocument
();
if
(
$doc
[
"ok"
])
{
return
$doc
[
"values"
];
}
throw
$this
->
_generateCommandException
(
$doc
);
}
/* }}} */
function
getDistinctOptions
()
{
/* {{{ */
return
array
(
/**
* The maximum amount of time to allow the query to run. The default is infinite.
*
* @see http://docs.mongodb.org/manual/reference/command/distinct/
*/
"maxTimeMS"
=>
0
,
);
}
/* }}} */
protected
function
_generateCommandException
(
$doc
)
{
/* {{{ */
if
(
$doc
[
"errmsg"
])
{
return
new
Exception
(
$doc
[
"errmsg"
]);
...
...
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