summaryrefslogtreecommitdiffstats
path: root/tests/auto/daemon/json/map-reduce.json
blob: 2736a9cd6a8e91472699e4c11b3d4d8134bb857b (plain)
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
[
  {
    "_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;}"
  }
]