Quantcast
Channel: 一言多いプログラマーの独り言
Viewing all articles
Browse latest Browse all 846

CouchDB(Cloudant)で検索Mango Query(Cloudant Query)の初歩(その2)

$
0
0
CouchDBCloudant)でMango Query(Cloudant Query)の初歩、その2です。CouchDBの「_find」の機能を利用すると良いらしい。MySQLで言うところの、「limit」や「offset」同等の機能も用意されています。これでページ送りを実現するのが賢いのかもしれません。


$app->get('/category/:category', function ($category) use ($app) {
$url = 'https://userid:password@bluemix.cloudant.com' ;
$client = new CouchClient($url, 'mydb');
$selector = [
'category' => ['$eq' => $category]
];
$fields = ['_id', 'category', 'title', 'create_at'];
$sort = ['create_at'=>'desc'] ;
$docs = $client->skip(0)->limit(10)->sort($sort)->fields($fields)->find($selector);
$app->render('category.twig', compact('docs', 'category'));
});

実際に設定してみたのがこちら

参考サイト
Mango Query(PHPOnCouch documentation)
/db/_find(Apache CouchDB Documentation)
MongoDB API layer for CouchDB(GitHub)

Viewing all articles
Browse latest Browse all 846

Trending Articles