제목에 따라 SQL에서 다음과 같은 PHP Mongo에 해당하는 내용은 무엇입니까?Mongo에 상응하는 SQL의 SELECT DISTINCT?
this table을 읽었지만 db.users.distinct('last_name')
를 PHP에 매핑하는 방법을 알지 못합니다.
제목에 따라 SQL에서 다음과 같은 PHP Mongo에 해당하는 내용은 무엇입니까?Mongo에 상응하는 SQL의 SELECT DISTINCT?
this table을 읽었지만 db.users.distinct('last_name')
를 PHP에 매핑하는 방법을 알지 못합니다.
command을 발급하고 distinct
키를 설정하십시오.
키의 고유 값을 모두 찾기.
<?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"));
foreach ($ages['values'] as $age) {
echo "$age\n";
}
?>
위 예제의 출력 :
4
22
87
당신이 절은 다음 구문을 사용 어디를 추가해야하는 경우 :이 답변은 '아무튼
$ages = $db->command(array(
"distinct" => "people",
"key" => "age",
"query" => array("someField" => "someValue")));
을 "WHERE"절 주소 지정 – monofonik