mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
Added another example to show that you can also pass in a query with distinct.
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@319248 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
e88ead0c09
commit
b290e3e418
1 changed files with 38 additions and 0 deletions
|
@ -139,6 +139,44 @@ foreach ($ages['values'] as $age) {
|
|||
<screen>
|
||||
4
|
||||
22
|
||||
87
|
||||
</screen>
|
||||
</example>
|
||||
<example>
|
||||
<title><function>MongoDB::command</function> "distinct" example</title>
|
||||
<para>
|
||||
Finding all of the distinct values for a key, where the value is larger
|
||||
than or equal to 18.
|
||||
</para>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
$people = $db->people;
|
||||
|
||||
$people->insert(array("name" => "Joe", "age" => 4));
|
||||
$people->insert(array("name" => "Sally", "age" => 22));
|
||||
$people->insert(array("name" => "Dave", "age" => 22));
|
||||
$people->insert(array("name" => "Molly", "age" => 87));
|
||||
|
||||
$ages = $db->command(
|
||||
array(
|
||||
"distinct" => "people",
|
||||
"key" => "age",
|
||||
"query" => array("age" => array('$gte' => 18))
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($ages['values'] as $age) {
|
||||
echo "$age\n";
|
||||
}
|
||||
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
&example.outputs.similar;
|
||||
<screen>
|
||||
22
|
||||
87
|
||||
</screen>
|
||||
</example>
|
||||
|
|
Loading…
Reference in a new issue