给定文件,如:
[
{"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"}
]
我希望能够传入类别并键入键并取回不同的行,例如传入 and 的键"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) {
...
});