40Isk42SiEdxW4yi4DuPsm changeset

Changeset333538336461 (b)
Parent323031643164 (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+// I am creating an accounting app; the transactions are stored using the following doc:
0+
0+{
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
...
88}
99
...
10-// REDUCE
10-function(keys, values, rereduce) {
10-        return true;
10-}
10+// Or they can be split acroll multiple accounts / categories / etc. In this case split over two categories:
...
1414
...
15-// SAMPLE DOC
...
1616{
...
17+   "_id": "405b791b64424d12e03c12e6e5002532",
17+   "_rev": "1-da46384d5f9fbfd26acbf8fc9a8e82fe",
...
1717   "type": "transaction",
1818   "account": "account_id",
1919   "payee": "Credit Card Company",
...
3030   ]
3131}
3232
...
33+// I have made a view to display all the unique categories in use across all transactions.
33+
33+// MAP
33+function (doc) {
33+    if (doc.type && doc.type == 'transaction') {
33+        if (doc.category) emit(doc.category);
33+        if (doc.split) doc.split.map(function (spl) {
33+            if (spl.category) emit(spl.category);
33+        });
33+    }
33+}
33+
33+// REDUCE
33+function(keys, values, rereduce) {
33+    return true;
33+}
33+
...
3333// CURRENT OUTPUT OF VIEW (with group=true)
3434{
3535        "rows": [
...
4444        ]
4545}
4646
...
47-// CURRENT OUTPUT OF VIEW (as temp view)
47+// CURRENT OUTPUT OF VIEW WHEN RUN AS A TEMPORARY VIEW (with group=true)
...
4848{
4949        "rows": [
5050                {
...
6161                }
6262        ]
6363}
...
64-// SIMPLIFIED VIEW
64-function(doc) {
64-        if (doc.type && doc.type == 'transaction') {
64-                emit(null,doc);
64-        }
64+
64+// SIMPLE TEST VIEW
64+function (doc) {
64+    if (doc.split) emit(null, doc.split);
...
6969}
7070
...
71-// OUTPUT
71-{
71-        "total_rows": 2,
71-        "offset": 0,
71-        "rows": [
71-                {
71-                        "id": "405b791b64424d12e03c12e6e5001535",
71-                        "key": null,
71-                        "value": {
71-                                "_id": "405b791b64424d12e03c12e6e5001535",
71-                                "_rev": "1-97d53ba31a6ebb8c0508d0fc8776fac5",
71-                                "type": "transaction",
71-                                "account": "account_id",
71-                                "payee": "Gas Company",
71-                                "description": "May Bill",
71-                                "date": "2009/05/25",
71-                                "status": "cleared",
71-                                "category": "Bills / Gas",
71-                                "value": -5000
71-                        }
71-                },
71-                {
71-                        "id": "405b791b64424d12e03c12e6e5002532",
71-                        "key": null,
71-                        "value": {
71-                                "_id": "405b791b64424d12e03c12e6e5002532",
71-                                "_rev": "1-da46384d5f9fbfd26acbf8fc9a8e82fe",
71-                                "type": "transaction",
71-                                "account": "account_id",
71-                                "payee": "Credit Card Company",
71-                                "description": "May Statement",
71-                                "date": "2009/06/02",
71-                                "status": "uncleared",
71-                                "category": "Debt / Credit Card Payments",
71-                                "value": -5000,
71-                                "split": [
71-                                ]
71-                        }
71-                }
71-        ]
71-}
71-
71-// OUTPUT OF DOC
71-{
71-        "_id": "405b791b64424d12e03c12e6e5002532",
71-        "_rev": "1-da46384d5f9fbfd26acbf8fc9a8e82fe",
71-        "type": "transaction",
71-        "account": "account_id",
71-        "payee": "Credit Card Company",
71-        "description": "May Statement",
71-        "date": "2009/06/02",
71-        "status": "uncleared",
71-        "category": "Debt / Credit Card Payments",
71-        "value": -5000,
71-        "split": [
71-                {
71-                        "category": "Dept / Default Charges",
71-                        "value": -1000
71-                }
71-        ]
71-}
71-
71-// TEST VIEW
71-function(doc) {
71-        if (doc.split) emit(null,doc.split);
71-}
71-
71-// OUTPUT OF TEMP VIEW
71+OUTPUT OF TEMP VIEW
...
139139{
140140        "total_rows": 1,
141141        "offset": 0,
...
153153        ]
154154}
155155
...
156-//OUTPUT OF SAME VIEW AFTER SAVE
156+OUTPUT OF SAME VIEW AFTER SAVE
...
157157{
158158        "total_rows": 1,
159159        "offset": 0,
...
166166                }
167167        ]
168168}
...
169+
169+It seems from the above that couch is for some reason returning the splits field as an empty array.
169+
169+Thanks for your time on IRC already.
169+
169+Cheers
169+
169+John
...
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
--- Revision 323031643164
+++ Revision 333538336461
@@ -1,20 +1,23 @@
-// 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);
- });
- }
+// I am creating an accounting app; the transactions are stored using the following doc:
+
+{
+ "_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
}
-// REDUCE
-function(keys, values, rereduce) {
- return true;
-}
+// Or they can be split acroll multiple accounts / categories / etc. In this case split over two categories:
-// SAMPLE DOC
{
+ "_id": "405b791b64424d12e03c12e6e5002532",
+ "_rev": "1-da46384d5f9fbfd26acbf8fc9a8e82fe",
"type": "transaction",
"account": "account_id",
"payee": "Credit Card Company",
@@ -31,6 +34,23 @@
]
}
+// I have made a view to display all the unique categories in use across all transactions.
+
+// 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;
+}
+
// CURRENT OUTPUT OF VIEW (with group=true)
{
"rows": [
@@ -45,7 +65,7 @@
]
}
-// CURRENT OUTPUT OF VIEW (as temp view)
+// CURRENT OUTPUT OF VIEW WHEN RUN AS A TEMPORARY VIEW (with group=true)
{
"rows": [
{
@@ -62,81 +82,13 @@
}
]
}
-// SIMPLIFIED VIEW
-function(doc) {
- if (doc.type && doc.type == 'transaction') {
- emit(null,doc);
- }
+
+// SIMPLE TEST VIEW
+function (doc) {
+ if (doc.split) emit(null, doc.split);
}
-// 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": [
- ]
- }
- }
- ]
-}
-
-// OUTPUT OF DOC
-{
- "_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": [
- {
- "category": "Dept / Default Charges",
- "value": -1000
- }
- ]
-}
-
-// TEST VIEW
-function(doc) {
- if (doc.split) emit(null,doc.split);
-}
-
-// OUTPUT OF TEMP VIEW
+OUTPUT OF TEMP VIEW
{
"total_rows": 1,
"offset": 0,
@@ -154,7 +106,7 @@
]
}
-//OUTPUT OF SAME VIEW AFTER SAVE
+OUTPUT OF SAME VIEW AFTER SAVE
{
"total_rows": 1,
"offset": 0,
@@ -167,3 +119,11 @@
}
]
}
+
+It seems from the above that couch is for some reason returning the splits field as an empty array.
+
+Thanks for your time on IRC already.
+
+Cheers
+
+John