• Share
  • Email
  • Embed
  • Like
  • Private Content
CouchConf-Chicago-Querying-with-Couchbase
 

CouchConf-Chicago-Querying-with-Couchbase

on

  • 805 views

 

Statistics

Views

Total Views
805
Views on SlideShare
804
Embed Views
1

Actions

Likes
1
Downloads
12
Comments
0

1 Embed 1

https://duckduckgo.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n

CouchConf-Chicago-Querying-with-Couchbase CouchConf-Chicago-Querying-with-Couchbase Presentation Transcript

  • 1
  • Queryingwith Couchbase 2
  • A View Is: 3
  • A View Is:A named pair of functions: a map function 3
  • A View Is:A named pair of functions: a map function a reduce function (optional) 3
  • A View Is:A named pair of functions: a map function a reduce function (optional)An entry in a design document 3
  • A View Is:A named pair of functions: a map function a reduce function (optional)An entry in a design documentA disk file of indexed results 3
  • A Map Function Is: 4
  • A Map Function Is:Called with every database document 4
  • A Map Function Is:Called with every database documentAn emitter of a key and a value 4
  • A Reduce Function Is: 5
  • A Reduce Function Is:Called once with the map results 5
  • A Reduce Function Is:Called once with the map resultsA simplifier (it reduces map output) 5
  • Example "President" Document (1 of 44) 6
  • Example "President" Document (1 of 44){ "_id":"5d5f25254ef8fd62d6b9f2db642a8fc2", "_rev": "1-157b2928bec2def71485cc751af7de37", "type":"president", "presidency":1, "name":"George Washington", "wikipedia_entry":"http://en.wikipedia.org/wiki/George_Washington", "took_office":1789, "left_office":1797, "party":"Independent", "home_state":"Virginia"} 6
  • Example "Event" Document (1 of 883) 7
  • Example "Event" Document (1 of 883){ "_id":"5d5f25254ef8fd62d6b9f2db642a9f7d", "_rev": "1-9630b35932dedbd4d31138aaf3385847", "type":"event", "year":1791, "event":"The independent Vermont Republic becomes the 14th state"} 7
  • Design Document{... "_id":"_design/design_document", "_rev": "1-9630b35932dedbd4d31138aaf3385847", "views": { "party_state_name": { "map":"function ... ", "reduce": " ... "}, "president_events": { "map":"function ... "}, "president_names": { "map":"function ... "}, "presidents": { "map":"function ... ", "reduce": " ... "}, "time_in_office": { "map":"function .... ", "reduce": " ... "}, "total_time_in_office": { "map":"function .... ", "reduce": " ... "} }, ...} 8
  • Design Document special{... "_id":"_design/design_document", "_rev": "1-9630b35932dedbd4d31138aaf3385847", "views": { "party_state_name": { "map":"function ... ", "reduce": " ... "}, "president_events": { "map":"function ... "}, "president_names": { "map":"function ... "}, "presidents": { "map":"function ... ", "reduce": " ... "}, "time_in_office": { "map":"function .... ", "reduce": " ... "}, "total_time_in_office": { "map":"function .... ", "reduce": " ... "} }, ...} 8
  • Design Document special you choose{... "_id":"_design/design_document", "_rev": "1-9630b35932dedbd4d31138aaf3385847", "views": { "party_state_name": { "map":"function ... ", "reduce": " ... "}, "president_events": { "map":"function ... "}, "president_names": { "map":"function ... "}, "presidents": { "map":"function ... ", "reduce": " ... "}, "time_in_office": { "map":"function .... ", "reduce": " ... "}, "total_time_in_office": { "map":"function .... ", "reduce": " ... "} }, ...} 8
  • president_names 9
  • Invoke a View 10
  • Invoke a Viewcurl -X GEThttp://localhost:5984/presidents/_design/design_doc/_view/president_names 11
  • Invoke a Viewcurl -X GEThttp://localhost:5984/presidents/_design/design_doc/_view/president_names{"total_rows":44,"offset":0,"rows":[ {"id":"...","key":1789,"value":"George Washington"}, {"id":"...","key":1797,"value":"John Adams"}, {"id":"...","key":1801,"value":"Thomas Jefferson"}, {"id":"...","key":1809,"value":"James Madison"}, ...]} emitting document ids are always included 11
  • Invoke a View 12
  • Invoke a View 12
  • Under the Hood: Views CouchDBSpidermonkey Disk ICU 13
  • Under the Hood: Viewshttp://localhost:5984/presidents/_design/design_doc/_view/president_names CouchDB Spidermonkey Disk ICU 13
  • Under the Hood: Views Erlang HTTPhttp://localhost:5984/presidents/_design/design_doc/_view/president_names CouchDB Spidermonkey Disk ICU 13
  • Under the Hood: Views Erlang HTTP mod_couchhttp://localhost:5984/presidents/_design/design_doc/_view/president_names CouchDB Spidermonkey Disk ICU 13
  • Under the Hood: Views Erlang HTTP mod_couch query server CouchDB storage enginehost:5984/presidents/_design/design_doc/_view/president_names Spidermonkey Disk ICU 13
  • Under the Hood: Views{"total_rows":44, "offset":0, "rows":[...]} Erlang HTTP mod_couch query server CouchDB storage engine view Spidermonkey Disk ICU 13
  • Under the Hood: Views{"total_rows":44, "offset":0, "rows":[...]} CouchDB Spidermonkey Disk ICU 14
  • Under the Hood: Views{"total_rows":44, "offset":0, "rows":[...]} {"id":"...","key":1789,"value":"George Washington"}, {"id":"...","key":1797,"value":"John Adams"}, ... CouchDB Spidermonkey Disk ICU 14
  • Fetch Documents Matching a KeyGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?key=1993 any valid JSON 15
  • Fetch Documents Matching a KeyGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?key=1993 total view rows offset into rows{"total_rows":44,"offset":41,"rows":[! ! {"id":"...","key":1993,"value":"Bill Clinton"}]} matching key 15
  • Invoke a View Text 16
  • Invoke a View Text 16
  • Query Parameters in the Java Clientquery = new Query();query.setKey(1993);view = client.getView("design_doc", "president_names");future = client.asyncQuery(view, query);viewResponse = future.get(); 17
  • Query Parameters in the Ruby ClientURL = ‘http://localhost:8091/pools/default’couchbase = Couchbase.new(URL)design_doc = couchbase.design_docs[‘design_doc’]design_doc.president_names(:key => 1993).fetch 18
  • Query Parameters in the PHP Client$cb = new Couchbase;$cb->addCouchbaseServer("localhost");$view = $cb->getView("design_doc", "president_names");$result = $view->getResultByKey(1993)); 19
  • Get a Key Range of DocumentsGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?startkey=1790&endkey=1810 20
  • Get a Key Range of DocumentsGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?startkey=1790&endkey=1810{"total_rows":44,"offset":1,"rows":[! {"id":"...","key":1797,"value":"John Adams"},! {"id":"...","key":1801,"value":"Thomas Jefferson"},! {"id":"...","key":1809,"value":"James Madison"}]} 20
  • Invoke a View 21
  • Invoke a View 21
  • Limit the Number of DocumentsGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?limit=2 22
  • Limit the Number of DocumentsGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?limit=2{"total_rows":44,"offset":0,"rows":[! {"id":"...","key":1789,"value":"George Washington"},! {"id":"...","key":1797,"value":"John Adams"},]} 22
  • Invoke a View 23
  • Invoke a View 23
  • presidents (_count) 24
  • Invoke a View 25
  • Reduce: _count{ "_id":"_design/design_doc", "_rev": "1-157b2928bec2def71485cc751af7de37", "views": { "presidents": { "map":"function(doc) { ! if(doc.type == president) { ! ! emit(doc.took_office, doc) }}", "reduce":"_count" } }, ...} 26
  • _count FunctionGET http://localhost:5984/presidents/_design/design_doc/_view/presidents 27
  • _count FunctionGET http://localhost:5984/presidents/_design/design_doc/_view/presidents{"rows":[! {"key":null,"value":44}]} 27
  • Invoke a View 28
  • Invoke a View 28
  • total_time_in_office (_sum) 29
  • Invoke a View 30
  • A Map Function for _sum{ "_id":"_design/design_doc", "_rev": "1-157b2928bec2def71485cc751af7de37", "views": { total_time_in_office": { "map":"function(doc) { ! ! if(doc.type == president) { ! ! ! emit(doc.name, doc.left_office - doc.took_office) ! }}", "reduce":"_sum" } }, ...} 31
  • A Map Function for _sum{ "_id":"_design/design_doc", "_rev": "1-157b2928bec2def71485cc751af7de37", "views": { total_time_in_office": { value is number of years in office "map":"function(doc) { ! ! if(doc.type == president) { ! ! ! emit(doc.name, doc.left_office - doc.took_office) ! }}", "reduce":"_sum" } }, will be sorted by name ...} 31
  • Reduce: _sum{ "_id":"_design/design_doc", "_rev": "1-157b2928bec2def71485cc751af7de37", "views": { total_time_in_office": { "map":"function(doc) { ! ! if(doc.type == president) { ! ! ! emit(doc.name, doc.left_office - doc.took_office) ! }}", "reduce":"_sum" } }, ...} 32
  • Reduce: _sum{ "_id":"_design/design_doc", "_rev": "1-157b2928bec2def71485cc751af7de37", "views": { total_time_in_office": { _sum requires number values "map":"function(doc) { ! ! if(doc.type == president) { ! ! ! emit(doc.name, doc.left_office - doc.took_office) ! }}", "reduce":"_sum" } }, ...} 32
  • _sum FunctionGET http://localhost:5984/presidents/_design/design_doc/_view/total_time_in_office 33
  • _sum FunctionGET http://localhost:5984/presidents/_design/design_doc/_view/total_time_in_office{"rows":[! {"key":null,"value":232}]} 33
  • Invoke a View 34
  • Invoke a View 34
  • time_in_office (_stats) 35
  • Invoke a View 36
  • Reduce: _stats{ "_id":"_design/design_doc", "_rev": "1-157b2928bec2def71485cc751af7de37", "views": { "time_in_office": { "map":"function(doc) { ! ! if(doc.type == president) { ! ! ! emit(doc.name, doc.left_office - doc.took_office) ! }}", "reduce":"_stats" } }, ...} 37
  • _stats FunctionGET http://localhost:5984/presidents/_design/design_doc/_view/time_in_office 38
  • _stats FunctionGET http://localhost:5984/presidents/_design/design_doc/_view/time_in_office{"rows":[! {"key":null,! "value":{ ! "sum":232,"count":43,"min":0,"max":12,"sumsqr":1546 }]} 38
  • Invoke a View 39
  • Invoke a View 39
  • View Trees 40
  • Disk-Based View Tree k=size of interior node A-R n=number of keys A-H I-Rdepth= log k(n) A-C D-F G-H I-L N-R A B C D F G H I K L N O Q R leaves 41
  • Disk-Based View Tree root k=size of interior node A-R n=number of keys A-H interior nodes I-Rdepth= log k(n) A-C D-F G-H I-L N-R A B C D F G H I K L N O Q R leaves 41
  • _count Nodes root 14 7 reductions 7 3 2 2 3 4A B C D F G H I K L N O Q R keys 42
  • _count Nodes root A-R 14 A-H 7 reductions I-R 7 A-C D-F G-H I-L N-R 3 2 2 3 4A B C D F G H I K L N O Q R keys 43
  • Inserting a New Document A-R 14 A-H I-R 7 7 A-C D-F G-H I-L N-R 3 2 2 3 4A B C D F G H I K L M N O Q R 44
  • Inserting a New Document A-R 14 A-H I-R 7 7 A-C D-F G-H I-L N-R 3 2 2 3 4A B C D F G H I K L M N O Q R new key 44
  • Inserting a New Document A-R 14 A-H I-R 7 7 M-R 5 A-C D-F G-H I-L N-R 3 2 2 3 4A B C D F G H I K L M N O Q R new key 44
  • Inserting a New Document A-R 14 I-R 8 A-H I-R 7 7 M-R 5 A-C D-F G-H I-L N-R 3 2 2 3 4A B C D F G H I K L M N O Q R new key 44
  • Inserting a New Document A-R 15 A-R 14 I-R 8 A-H I-R 7 7 M-R 5 A-C D-F G-H I-L N-R 3 2 2 3 4A B C D F G H I K L M N O Q R new key 44
  • Inserting a New Document new root A-R 15 A-R 14 new reductions I-R 8 A-H I-R 7 7 M-R 5 A-C D-F G-H I-L N-R 3 2 2 3 4A B C D F G H I K L M N O Q R new key 44
  • Committing the Change A-R 15 A-R 14 I-R 8 A-H I-R 7 7 M-R 5 A-C D-F G-H I-L N-R 3 2 2 3 4A B C D F G H I K L M N O Q R 45
  • Committing the Change A-R 15 14 A-H I-R 7 87 A-C D-F G-H I-L M-R N-R 3 2 2 3 5 4A B C D F G H I K L M N O Q R 45
  • Getting a Key Range A-R 14 A-H I-R 7 7 A-C D-F G-H I-L M-R 3 2 2 3 5A B C D F G H I K L M N O Q R startkey endkey 46
  • Key Range Reduction 15 7 8 3 2 2 3 5A B C D F G H I K L M N O Q R startkey endkey 47
  • Key Range Reduction 15 (8) (3) 7 8 (5) 3 (1) 2 2 3 5 (2)A B C D F G H I K L M N O Q R startkey endkey 47
  • More Ways to Use Views 48
  • Skip the Reduce FunctionGET http://localhost:5984/presidents/_design/design_doc/_view/time_in_office?reduce=false 49
  • Skip the Reduce FunctionGET http://localhost:5984/presidents/_design/design_doc/_view/time_in_office?reduce=false{"total_rows":44,"offset":0,"rows":[ {"id":"...","key":"Abraham Lincoln","value":5}, {"id":"...","key":"Andrew Jackson","value":8}, {"id":"...","key":"Andrew Johnson","value":4}, ...]} 49
  • Invoke a View 50
  • Invoke a View 50
  • Reversing the Order of ResultsGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?descending=true 51
  • Reversing the Order of ResultsGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?descending=true{"total_rows":44,"offset":0,"rows":[ {"id":"...","key":2009,"value":"Barack Obama"}, {"id":"...","key":2001,"value":"George W. Bush"}, {"id":"...","key":1993,"value":"Bill Clinton"}, {"id":"...","key":1989,"value":"George H. W. Bush"}, ...]} 51
  • Invoke a View 52
  • Invoke a View 52
  • Reversing the Order of a RangeGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?descending=true&startkey=1850&endkey=1790 53
  • Reversing the Order of a Range startkey and endkey are reversed, tooGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?descending=true&startkey=1850&endkey=1790 53
  • Reversing the Order of a Range startkey and endkey are reversed, tooGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?descending=true&startkey=1850&endkey=1790{"total_rows":44,"offset":0,"rows":[ {"id":"...","key":2009,"value":"Barack Obama"}, {"id":"...","key":2001,"value":"George W. Bush"}, {"id":"...","key":1993,"value":"Bill Clinton"}, {"id":"...","key":1989,"value":"George H. W. Bush"}, ...]} 53
  • Invoke a View 54
  • Invoke a View 54
  • Ignore a Given Number of RowsGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?limit=10&skip=1 55
  • Ignore a Given Number of RowsGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?limit=10&skip=1 avoid large values 55
  • Invoke a View 56
  • Invoke a View 56
  • Paginating (Initial Page)// first page of documentsGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?limit=2 57
  • Paginating (Initial Page)// first page of documentsGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?limit=2{"total_rows":44,"offset":0,"rows":[! {"id":"...","key":1789,"value":"George Washington"},! {"id":"...","key":1797,"value":"John Adams"},]} last key of result 57
  • Paginating (Successive Pages) 58
  • Paginating (Successive Pages) last key of previous result// successive pagesGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?startkey=1797&skip=1&limit=2 dont include the first document 58
  • Paginating (Successive Pages)// successive pagesGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?startkey=1797&skip=1&limit=2{"total_rows":44,"offset":2,"rows":[! {"id":"...","key":1801,"value":"Thomas Jefferson"},! {"id":"...","key":1809,"value":"James Madison"},]} 58
  • Invoke a View 59
  • Invoke a View 59
  • Paginating in Reverse Order// first page of documentsGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?descending=true&limit=2 60
  • Paginating in Reverse Order// first page of documentsGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?descending=true&limit=2// successive pages last key of previous resultGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?descending=true&startkey=1797&skip=1&limit=2 dont include the first document 60
  • Invoke a View 61
  • Invoke a View 61
  • Using a Stale ViewGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?stale=ok 62
  • Invoke a View 63
  • Invoke a View 63
  • Invoke a View 64
  • Invoke a View 64
  • Invoke a View 65
  • Invoke a View 65
  • Invoke a View 66
  • Invoke a View 66
  • Updating the View Immediately AfterGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?stale=update_after 67
  • party_state_name(group & group_level) 68
  • Invoke a View 69
  • group_level=1Map Keys Group Level 1["a",1,1] {"key":["a"], "value":3}["a",3,4]["a",3,8]["b",2,6] {"key":["b"], "value":2}["b",2,6]["c",1,5] {"key":["c"], "value":2}["c",4,2] 70
  • group_level=1 Map Keys Group Level 1 ["a",1,1] {"key":["a"], "value":3} ["a",3,4] ["a",3,8] ["b",2,6] {"key":["b"], "value":2} ["b",2,6] ["c",1,5] {"key":["c"], "value":2} ["c",4,2] GET http://localhost:5984/my_db/_design/ddoc/_view/v1? group_level=1only applies to reduce views 70
  • group_level=2Map Keys Group Level 2["a",1,1] {"key":["a",1], "value":1}["a",3,4] {"key":["a",3], "value":2}["a",3,8]["b",2,6] {"key":["b",2], "value":2}["b",2,6]["c",1,5] {"key":["c",1], "value":1}["c",4,2] {"key":["c",4], "value":1} 71
  • group_level=2 Map Keys Group Level 2 ["a",1,1] {"key":["a",1], "value":1} ["a",3,4] {"key":["a",3], "value":2} ["a",3,8] ["b",2,6] {"key":["b",2], "value":2} ["b",2,6] ["c",1,5] {"key":["c",1], "value":1} ["c",4,2] {"key":["c",4], "value":1} GET http://localhost:5984/my_db/_design/ddoc/_view/v1? group_level=2only applies to reduce views 71
  • Invoke a View 72
  • Group Level 73
  • Group Level 73
  • Group Level 74
  • Group Level 74
  • Group 75
  • Group GET http://localhost:5984/my_db/_design/greeting/_view/v1? group=true one output row for each unique keyequivalent to group_level=infinity 75
  • Group Level 76
  • Group Level 76
  • Including Full DocumentsGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?include_docs=true 77
  • Including Full DocumentsGET http://localhost:5984/presidents/_design/design_doc/_view/president_names?include_docs=true{"total_rows":44,"offset":0,"rows":[{"id":"...","key":1789,"value":"George Washington","doc":{"_id":"...","_rev":"1-...","presidency":"1","wikipedia_entry":"http://en.wikipedia.org/...","took_office":1789,"left_office":1797,"party":"Independent","home_state":"Virginia","name":"George Washington","type":"president"}},! ,...]} 77
  • Group Level 78
  • Group Level 78
  • Emitting with include_docs=true 79
  • Emitting with include_docs=true includes the latest rev of the emitterfunction(doc) { emit("key", aValue) } 79
  • Emitting with include_docs=true includes the latest rev of the emitterfunction(doc) { emit("key", aValue) } includes this rev of the emitterfunction(doc) { emit("key",{"_rev":doc._rev; aValue}) } 79
  • Emitting with include_docs=true includes the latest rev of the emitterfunction(doc) { emit("key", aValue) } includes this rev of the emitterfunction(doc) { emit("key",{"_rev":doc._rev; aValue}) } includes document with id foofunction(doc) { emit("key",{"_id":"foo", aValue}) } 79
  • Requesting Specific Keys 80
  • Requesting Specific KeysPOST -H "Content-Type:application/json"http://localhost:5984/presidents/_design/design_doc/_view/president_names-d {"keys":[1789, 1929, 1993, ... ]} 80
  • Requesting Specific KeysPOST -H "Content-Type:application/json"http://localhost:5984/presidents/_design/design_doc/_view/president_names-d {"keys":[1789, 1929, 1993, ... ]}POST -H "Content-Type:application/json"http://localhost:5984/presidents/_design/design_doc/_view/president_names?include_docs=true-d {"keys":[1789, 1929, 1993, ... ]} 80
  • Group Level 81
  • Group Level 81
  • president_events (join) 82
  • Invoke a View 83
  • Collating Joins"views": { "president_events": "function(doc) { if (doc.type == president) { emit([doc.took_office], doc.name); } else if (doc.type == event) { emit([doc.year, 0], doc.event); } }"} 84
  • Collating Joins year took office"views": { "president_events": "function(doc) { if (doc.type == president) { emit([doc.took_office], doc.name); } else if (doc.type == event) { emit([doc.year, 0], doc.event); } }"} 84
  • Collating Joins year took office"views": { one-element array "president_events": "function(doc) { if (doc.type == president) { emit([doc.took_office], doc.name); } else if (doc.type == event) { emit([doc.year, 0], doc.event); } }"} 84
  • Collating Joins year took office"views": { one-element array "president_events": "function(doc) { if (doc.type == president) { emit([doc.took_office], doc.name); } else if (doc.type == event) { emit([doc.year, 0], doc.event); } }" year of event} 84
  • Collating Joins year took office"views": { one-element array "president_events": "function(doc) { if (doc.type == president) { emit([doc.took_office], doc.name); } else if (doc.type == event) { emit([doc.year, 0], doc.event); } }" year of event} second array element 84
  • Join Presidents and EventsGET http://localhost:5984/presidents/_design/design_doc/_view/president_events 85
  • Join Presidents and EventsGET http://localhost:5984/presidents/_design/design_doc/_view/president_events{"total_rows":883,"offset":0,"rows":[ {"id":"...","key":[1789],"value":"George Washington"}, {"id":"...","key":[1790,0],"value":"Rhode Island ratifies the Constitution and becomes 13th state"}, {"id":"...","key":[1791,0],"value":"Bill of Rights ratified"}, {"id":"...","key":[1791,0],"value":"First Bank of the United States chartered"}, ...]} 85
  • Group Level 86
  • Group Level 86
  • Viewshttp://alan.iriscouch.com/presidents/_design/design_docPresidents Filehttp://alan.iriscouch.com/presidents/_design/design_doc/presidents.jsonEvents Filehttp://alan.iriscouch.com/presidents/_design/design_doc/us_events.json 87
  • Thanks! 88