MongoDB에서 distinct기능을 사용하기 위해서는 command라는 기능을 이용해야 한다. command라는 function에 어떠한 Collection의 어느 Field에 대해서 distinct기능을 사용할 것인지를 명시해주어야 한다.
아래 예제는 해당 기능을 사용하는 예제를 php로 작성한 것이다.
이 페이지의 기능은 referCollection에서 unique한 refererIdList를 얻어온뒤, 해당 ID를 이용해 page객체를 가져오는 기능이 되겠다.
<?php
require_once ('Config.php');
$testMongo = MongodbUtil::getTestMongoDB();
$referersCol = $testMongo->referers;
$pagesCol = $testMongo->pages;
$referers = $testMongo->command(array("distinct"=>"referers", "key"=>"objId"));
header ("Content-type: text/html;charset=utf8");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<br><br>
<table border=1>
<tr>
<td><b>Index</b></td>
<td><b>Name</b></td>
<td><b>Category</b></td>
<td><b>Subject</b></td>
</tr>
<tr>
<td><b><?php echo $index; ?></b></td>
<td><b><?php echo $pageName; ?></b></td>
<td><b><?php echo $categoryName; ?></b></td>
<td><b><?php echo $subject; ?></b></td>
</tr>
</html>
'Programming > NoSQL' 카테고리의 다른 글
| MongoDB PHP Driver에서 distinct기능 활용하기 (0) | 2011/08/01 |
|---|---|
| MongoDB 적용사례 (0) | 2011/07/13 |
| NoSQL에 대한 고찰 (15) | 2010/11/30 |
| MongoDB 성능 테스팅 (2) | 2010/11/02 |
| MongoDB Java Driver에서 IN Query사용하기 (0) | 2010/11/02 |
| MongoDB Select 예제 (0) | 2010/10/26 |