Given documents like:
[
{"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"}
]
I want to be able to pass in the category and type keys and get back the distinct lines e.g. pass in keys of "cat1"
and "type1"
and get back ["line1", "line2"]
or pass in "cat2"
and "type1"
and get back ["line2", "line3"]
Easier enough if I am not passing in keys:
map
function(doc) {
emit([doc.line]);
}
reduce
function(keys, values) {
return null;
}
I am using group: true, but stumped on how to handle this when passing in keys.
PS, using node and nano so query looks similar to:
db.view('catalog', 'lines', {key: ['cat1', 'type1'], group: true}, function (err, body) {
...
});