summaryrefslogtreecommitdiffstats
path: root/tests/auto/partition/json/map-reduce.json
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/partition/json/map-reduce.json')
-rw-r--r--tests/auto/partition/json/map-reduce.json80
1 files changed, 80 insertions, 0 deletions
diff --git a/tests/auto/partition/json/map-reduce.json b/tests/auto/partition/json/map-reduce.json
new file mode 100644
index 00000000..2736a9cd
--- /dev/null
+++ b/tests/auto/partition/json/map-reduce.json
@@ -0,0 +1,80 @@
+[
+ {
+ "_type": "Contact",
+ "displayName": "Joe Smith",
+ "name": {
+ "firstName": "joe",
+ "lastName": "smith"
+ },
+ "preferredNumber": "+15555551212",
+ "phoneNumbers": [
+ {
+ "type": "mobile",
+ "number": "+15555551212"
+ },
+ {
+ "type": "work",
+ "number": "+17812232323"
+ },
+ {
+ "type": "home",
+ "number": "+16174532300"
+ }
+ ]
+ },
+ {
+ "_type": "Contact",
+ "displayName": "Nancy Doe",
+ "name": {
+ "firstName": "nancy",
+ "lastName": "doe"
+ },
+ "preferredNumber": "+14567891234",
+ "phoneNumbers": [
+ {
+ "type": "mobile",
+ "number": "+14567891234"
+ },
+ {
+ "type": "home",
+ "number": "+16174532322"
+ }
+ ]
+ },
+ {
+ "_type": "_schemaType",
+ "name": "Phone",
+ "schema": {
+ "type": "object",
+ "extends": {"$ref": "View"}
+ }
+ },
+ {
+ "_type": "_schemaType",
+ "name": "PhoneCount",
+ "schema": {
+ "type": "object",
+ "extends": {"$ref": "View"}
+ }
+ },
+ {
+ "_type": "Map",
+ "targetType": "Phone",
+ "map": {"Contact": "function (c) {\
+ for (var i in c.phoneNumbers) {\
+ var phone = c.phoneNumbers[i];\
+ var id = c.displayName + ':' + phone.number; \
+ var uuid = jsondb.createUuidFromString(id); \
+ jsondb.emit({_uuid: uuid, key: phone.number, displayName: c.displayName});\
+ }\
+ }"}
+ },
+ {
+ "_type": "Reduce",
+ "targetType": "PhoneCount",
+ "sourceType": "Phone",
+ "sourceKeyName": "key",
+ "add": "function add (k, z, c) { if (!z) {z = {count: 0}}; z.count += 1; return z;}",
+ "subtract": "function subtract (k, z, c) { if (!z) {z = {count: 0}}; z.count -= 1; if (z.count) return z;}"
+ }
+]