| a | b | |
|---|
| 0 | + | // MAP |
|---|
| 0 | + | function(doc) { |
|---|
| 0 | + | if (doc.type && doc.type == 'transaction') { |
|---|
| 0 | + | if (doc.category) emit(doc.category); |
|---|
| 0 | + | if (doc.split) doc.split.map(function(spl) { |
|---|
| 0 | + | if (spl.category) emit(spl.category); |
|---|
| 0 | + | }); |
|---|
| 0 | + | } |
|---|
| 0 | + | } |
|---|
| 0 | + | |
|---|
| 0 | + | // REDUCE |
|---|
| 0 | + | function(keys, values, rereduce) { |
|---|
| 0 | + | return true; |
|---|
| 0 | + | } |
|---|
| 0 | + | |
|---|
| 0 | + | // SAMPLE DOC |
|---|
| 0 | + | { |
|---|
| 0 | + | "type": "transaction", |
|---|
| 0 | + | "account": "account_id", |
|---|
| 0 | + | "payee": "Credit Card Company", |
|---|
| 0 | + | "description": "May Statement", |
|---|
| 0 | + | "date": "2009/06/02", |
|---|
| 0 | + | "status": "uncleared", |
|---|
| 0 | + | "category": "Debt / Credit Card Payments", |
|---|
| 0 | + | "value": -5000, |
|---|
| 0 | + | "split": [ |
|---|
| 0 | + | { |
|---|
| 0 | + | "category": "Dept / Default Charges", |
|---|
| 0 | + | "value": -1000 |
|---|
| 0 | + | } |
|---|
| 0 | + | ] |
|---|
| 0 | + | } |
|---|
| 0 | + | |
|---|
| 0 | + | // CURRENT OUTPUT OF VIEW (with group=true) |
|---|
| 0 | + | { |
|---|
| 0 | + | "rows":[ |
|---|
| 0 | + | {"key":"Bills / Gas","value":true}, |
|---|
| 0 | + | {"key":"Debt / Credit Card Payments","value":true} |
|---|
| 0 | + | ]} |
|---|
| 0 | + | |
|---|
| 0 | + | // SIMPLIFIED VIEW |
|---|
| 0 | + | function(doc) { |
|---|
| 0 | + | if (doc.type && doc.type == 'transaction') { |
|---|
| 0 | + | emit(null,doc); |
|---|
| 0 | + | } |
|---|
| 0 | + | } |
|---|
| 0 | + | |
|---|
| 0 | + | // OUTPUT |
|---|
| 0 | + | { |
|---|
| 0 | + | "total_rows": 2, |
|---|
| 0 | + | "offset": 0, |
|---|
| 0 | + | "rows": [ |
|---|
| 0 | + | { |
|---|
| 0 | + | "id": "405b791b64424d12e03c12e6e5001535", |
|---|
| 0 | + | "key": null, |
|---|
| 0 | + | "value": { |
|---|
| 0 | + | "_id": "405b791b64424d12e03c12e6e5001535", |
|---|
| 0 | + | "_rev": "1-97d53ba31a6ebb8c0508d0fc8776fac5", |
|---|
| 0 | + | "type": "transaction", |
|---|
| 0 | + | "account": "account_id", |
|---|
| 0 | + | "payee": "Gas Company", |
|---|
| 0 | + | "description": "May Bill", |
|---|
| 0 | + | "date": "2009/05/25", |
|---|
| 0 | + | "status": "cleared", |
|---|
| 0 | + | "category": "Bills / Gas", |
|---|
| 0 | + | "value": -5000 |
|---|
| 0 | + | } |
|---|
| 0 | + | }, |
|---|
| 0 | + | { |
|---|
| 0 | + | "id": "405b791b64424d12e03c12e6e5002532", |
|---|
| 0 | + | "key": null, |
|---|
| 0 | + | "value": { |
|---|
| 0 | + | "_id": "405b791b64424d12e03c12e6e5002532", |
|---|
| 0 | + | "_rev": "1-da46384d5f9fbfd26acbf8fc9a8e82fe", |
|---|
| 0 | + | "type": "transaction", |
|---|
| 0 | + | "account": "account_id", |
|---|
| 0 | + | "payee": "Credit Card Company", |
|---|
| 0 | + | "description": "May Statement", |
|---|
| 0 | + | "date": "2009/06/02", |
|---|
| 0 | + | "status": "uncleared", |
|---|
| 0 | + | "category": "Debt / Credit Card Payments", |
|---|
| 0 | + | "value": -5000, |
|---|
| 0 | + | "split": [ |
|---|
| 0 | + | ] |
|---|
| 0 | + | } |
|---|
| 0 | + | } |
|---|
| 0 | + | ] |
|---|
| 0 | + | } |
|---|
| 0 | + | |
|---|
| 0 | + | |
|---|
| ... | |
|---|