(PECL mongo >=1.2.11)
MongoCollection::distinct — 锟斤拷取锟斤拷锟斤拷锟斤拷指锟斤拷锟斤拷锟侥诧拷同值锟斤拷锟叫憋拷
$key
[, array $query
] ) : arraydistinct 锟斤拷锟筋返锟截硷拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟酵碉拷锟斤拷斜锟�
key
要使锟矫的硷拷锟斤拷
query
一锟斤拷锟斤拷选锟侥诧拷询锟斤拷锟斤拷
锟斤拷锟截诧拷同值锟斤拷锟斤拷锟介, 锟斤拷锟斤拷锟斤拷失锟斤拷时锟斤拷锟斤拷 FALSE
Example #1 MongoCollection::distinct() 锟斤拷锟斤拷
<?php
$m = new Mongo;
$db = $m->selectDB("test");
$db->dropCollection("distinct");
$c = $db->distinct;
$c->insert(array("stuff" => "bar", "zip-code" => 10010));
$c->insert(array("stuff" => "foo", "zip-code" => 10010));
$c->insert(array("stuff" => "bar", "zip-code" => 99701), array("w" => 1));
$retval = $c->distinct("zip-code");
var_dump($retval);
$retval = $c->distinct("zip-code", array("stuff" => "foo"));
var_dump($retval);
$retval = $c->distinct("zip-code", array("stuff" => "bar"));
var_dump($retval);
?>
锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�
array(2) { [0]=> int(10010) [1]=> int(99701) } array(1) { [0]=> int(10010) } array(2) { [0]=> int(10010) [1]=> int(99701) }
Example #2 锟斤拷嵌锟侥碉拷锟斤拷 MongoCollection::distinct() 锟斤拷锟斤拷
<?php
$c->insert(array("user" => array("points" => 25)));
$c->insert(array("user" => array("points" => 31)));
$c->insert(array("user" => array("points" => 25)));
$retval = $c->distinct("user.points");
var_dump($retval);
$retval = $c->distinct("user.nonexisting");
var_dump($retval);
?>
锟斤拷锟斤拷锟斤拷锟教伙拷锟斤拷锟斤拷锟�
array(2) { [0]=> int(25) [1]=> int(31) } array(0) { }