40Isk42SiEdxW4yi4DuPsm changeset

Changeset363365323938 (b)
ParentNone (a)
ab
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+
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
--- Revision None
+++ Revision 363365323938
@@ -0,0 +1,90 @@
+// MAP
+function(doc) {
+ if (doc.type && doc.type == 'transaction') {
+ if (doc.category) emit(doc.category);
+ if (doc.split) doc.split.map(function(spl) {
+ if (spl.category) emit(spl.category);
+ });
+ }
+}
+
+// REDUCE
+function(keys, values, rereduce) {
+ return true;
+}
+
+// SAMPLE DOC
+{
+ "type": "transaction",
+ "account": "account_id",
+ "payee": "Credit Card Company",
+ "description": "May Statement",
+ "date": "2009/06/02",
+ "status": "uncleared",
+ "category": "Debt / Credit Card Payments",
+ "value": -5000,
+ "split": [
+ {
+ "category": "Dept / Default Charges",
+ "value": -1000
+ }
+ ]
+}
+
+// CURRENT OUTPUT OF VIEW (with group=true)
+{
+ "rows":[
+ {"key":"Bills / Gas","value":true},
+ {"key":"Debt / Credit Card Payments","value":true}
+]}
+
+// SIMPLIFIED VIEW
+function(doc) {
+ if (doc.type && doc.type == 'transaction') {
+ emit(null,doc);
+ }
+}
+
+// OUTPUT
+{
+ "total_rows": 2,
+ "offset": 0,
+ "rows": [
+ {
+ "id": "405b791b64424d12e03c12e6e5001535",
+ "key": null,
+ "value": {
+ "_id": "405b791b64424d12e03c12e6e5001535",
+ "_rev": "1-97d53ba31a6ebb8c0508d0fc8776fac5",
+ "type": "transaction",
+ "account": "account_id",
+ "payee": "Gas Company",
+ "description": "May Bill",
+ "date": "2009/05/25",
+ "status": "cleared",
+ "category": "Bills / Gas",
+ "value": -5000
+ }
+ },
+ {
+ "id": "405b791b64424d12e03c12e6e5002532",
+ "key": null,
+ "value": {
+ "_id": "405b791b64424d12e03c12e6e5002532",
+ "_rev": "1-da46384d5f9fbfd26acbf8fc9a8e82fe",
+ "type": "transaction",
+ "account": "account_id",
+ "payee": "Credit Card Company",
+ "description": "May Statement",
+ "date": "2009/06/02",
+ "status": "uncleared",
+ "category": "Debt / Credit Card Payments",
+ "value": -5000,
+ "split": [
+ ]
+ }
+ }
+ ]
+}
+
+