Hi Alex!

> I've been poking at how to construct views using the map reduce mechanics but 
> am struggling with crafting a particular view.  I have a set of data where 
> documents have a category and I'd like to have a view that provides me with 
> groups of documents based on their category.  Is it possible to get the 
> following three documents into the subsequent view (loosely defined)?
> 
> * { "category": "A", "_id": "1" }
> * { "category": "A", "_id": "2" }
> * { "category": "B", "_id": "3" }
> 
> View:
> 
> { "A": [ { "category": "A", "_id": "1" }, { "category": "A", "_id": "2" } ], 
> "B": [ { "category": "B", "_id": "3" } ] }

Don’t try to group category members in the “value” of a view row. Just emit a 
row per doc with the category as key and request the key:

====

function () {
  emit(doc.category, null)     //the doc._id is automatically included
}

====

GET db/_design/:ddocname/_view/:viewname?key=‘A’

====

{
  rows: [
    {id: “1”, key: “A”, value: null},
    {id: “2”, key: “A”, value: null}
  ]
}


Best, ingo

Reply via email to