次のようなドキュメントが与えられた場合:
[
{"id":1, "category": "cat1", "type": "type1", "line": "line1"},
{"id":2, "category": "cat1", "type": "type1", "line": "line1"},
{"id":3, "category": "cat1", "type": "type2", "line": "line1"},
{"id":4, "category": "cat1", "type": "type1", "line": "line2"},
{"id":5, "category": "cat2", "type": "type1", "line": "line2"},
{"id":6, "category": "cat2", "type": "type1", "line": "line3"}
]
カテゴリを渡してキーを入力し、個別の行を取得できるように"cat1"
し"type1"
たい.["line1", "line2"]
"cat2"
"type1"
["line2", "line3"]
キーを渡さない場合は簡単です:
地図
function(doc) {
emit([doc.line]);
}
減らす
function(keys, values) {
return null;
}
私は group: true を使用していますが、キーを渡すときにこれを処理する方法に困惑しています。
PS、ノードとナノを使用しているため、クエリは次のようになります。
db.view('catalog', 'lines', {key: ['cat1', 'type1'], group: true}, function (err, body) {
...
});