Your SlideShare is downloading. ×

Developing ii advanced document design

516

Published on

Published in: Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
516
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Advanced Document Design Benjamin Young benjamin@couchbase.com @bigbluehat
  • 2. ● "User Advocate" ● User Experience Engineers ● + T Evangelist ech● Entrepreneur for 7+ years ● built BlueInk, a CMS● Couch.io/CouchOne in 2010 ● did User Advocate stuff● Co-Organizer of REST Fest (www.restfest.org)● Couchbase in 2011+ ● build UIs, make sample apps, give talks
  • 3. Agenda● Document Databases ● Schema-less Data Modeling ● Inherent Constraints● Document Design Basics ● living in the world of Documents● Getting at your Documents (with Demos!) ● Document Editing Demo ● Creating Views and Indexes ● Querying those Indexes ● Reducing the output to values● Questions
  • 4. Document DatabasesDocument Document DesignDatabases Basics Creating Demonstration Summary Views of View Editing
  • 5. Schema-less Data Modeling● ad hoc data store ● No ALTER T ABLE ● Add new " fields" to any object any time ● improves development speed● Structure matters at query time, not write time● JSON data is interoperable ● 2.0 Features ● dynamic queries with views ● “Web-native” format ● broad language support: json.org
  • 6. Inherent Constraints● Document ID is the only (DB-side) way to enforce uniqueness● JSON doc key name restrictions ● top-level keys may not begin with either “_” or “$”● Small “gotchas” ● watch out for numbers as strings (Reduce will care) ● data format consistency ● unix time stamps ● some other JS parse-able, IETF codified format
  • 7. Document Design BasicsDocument Document DesignDatabases Basics Creating Demonstration Summary Views of View Editing
  • 8. Beer Document type name in ID{  "_id": "beer_1554_Enlightened_Black_Ale",  "brewery": "New Belgium Brewing", used to reference  "name": "1554 Enlightened Black Ale", the brewery doc  "abv": "5.5", in MapReduce  "description": "Born of a flood...",  "category": "Belgian and French Ale",  "style": "Other Belgian-Style Ales",  "updated": "2010-07-22 20:00:20"} “vintage” date from an SQL dump >_<
  • 9. Brewery Document type name in ID{"_id": "brewery_New_Belgium_Brewing",  "name": "New Belgium Brewing",  "address": ["500 Linden Street"], JSON array  "city": "Fort Collins",  "state": "Colorado",  "code": "80524",  "website": "http://www.newbelgium.com/",  "description": "Well set the scene...”,  "geo": { GeoCouch FTW!     "loc": ["-105.07", "40.5929"],     "accuracy": "RANGE_INTERPOLATED"  },  "updated": "2010-07-22 20:00:20"}
  • 10. Creating Views Couchbase Server 2.0: Querying and Aggregation with ViewsDocument Document DesignDatabases Basics Creating Demonstration Summary Views of View Editing
  • 11. Document Editing Demo
  • 12. Couchbase Server 2.0:Querying and Aggregation with Views
  • 13. MapReduce Basics● Building indexes, not querying ● Eventually Consistent indexed view ● “Secondary Index”● Output keys are used to reference ranges of the index● Document IDs can also be used for referencing● “Querying” is done via the Query String ● the SDKs wrap this up for you● Values can be anything● Reduce is an additional layer
  • 14. Map function to build the Index of Breweries and their Beers_design/beers/_view/brewery_beersfunction(doc) { if (doc.geo) { emit([humanize(doc._id)], 1); } else if (doc.brewery && typeof doc.brewery === string) { emit([doc.brewery, humanize(doc._id)], 1); } // handy function for building IDs from names function humanize(name) { return name.replace(/^(brewery_|beer_)/, ) .replace(/_/g, ); }}
  • 15. Built-in Reduce function for the Brewery and their Beers_design/beers/_view/brewery_beers?reduce=true_count• Built-in reducers are the fastest option for Index reduction• _count• _sum• _stats (min, max, count, avg)
  • 16. View EditingDocument Document DesignDatabases Basics Creating Demonstration Summary Views of View Editing
  • 17. Views Editing Demo
  • 18. Results from the brewery_beers index_design/beers/_view/brewery_beers{"rows": [ {"id": "brewery_Abhi_Brewery", "key": ["Abhi Brewery"], "value": 1 }, {"id": "beer_Abhi_beer", "key": ["Abhi Brewery","Abhi beer"], "value": 1 }]}
  • 19. Wait...wheres the data? Meet ?include_docs=true
  • 20. Results from the brewery_beers index_design/beers/_view/brewery_beers?include_docs=true{"rows": [ {"id": "brewery_Abhi_Brewery", "key": ["Abhi Brewery"], "value": 1, "doc": { "_id": "brewery_Abhi_Brewery", "name": "Abhi Brewery", .... } }, {"id": "beer_Abhi_beer", "key": ["Abhi Brewery","Abhi beer"], "value": 1, "doc": { "_id": "beer_Abhi_beer", "name": "Abhi beer", ....} }]}
  • 21. Results from the brewery_beers index_design/beers/_view/brewery_beers?startkey=["New Belgium Brewing"]&endkey=["New Belgium Brewing", {}]{"rows": [ {"id": "brewery_New_Belgium_Brewing", "key": ["New Belgium Brewing"], "value": 1, "doc": { "_id": "brewery_New_Belgium_Brewing", "name": "New Belgium Brewing", .... } }, {"id": "beer_Fat_Tire_Amber_Ale", "key": ["New Belgium Brewing", "Fat Tire Amber Ale"], "value": 1, "doc": { "_id": "beer_Fat_Tire_Amber_Ale", "name": "Fat Tire Amber Ale", ....} } ]}
  • 22. Number of Beers per Brewery using Reduce_design/beers/_view/brewery_beers?group_level=1{"rows": [ {"id": "brewery_New_Belgium_Brewing", "key": ["New Belgium Brewing"], "value": 9, {"id": "brewery_Other_Brewery", "key": ["Other Brewery"], "value": 3]}• Values are the full count of docs beginning in this range• subtract one (in this case) to find the # of beer docs
  • 23. Creating Views Couchbase Server 2.0: Querying and Aggregation with ViewsDocument Document DesignDatabases Basics Creating Demonstration Summary Views of View Editing
  • 24. Summary● Schema-less Document Databases● Document Design ● you deal in docs daily● View Index Building ● schema on the " way out"
  • 25. Questions?
  • 26. Thanks! Benjamin Youngbenjamin@couchbase.com @bigbluehat

×