Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introducing Apache CouchDB 2.0 at ApacheCon

Introducing Apache CouchDB 2.0 at ApacheCon

Apache CouchDB is a document database featuring an HTTP API, JSON documents, and peer-to-peer replication. Take a tour of the upcoming features and improvements in Apache CouchDB 2.0 including clustering capabilities for horizontal scalability and a declarative MongoDB-style ad hoc querying system. This talk should be of interest to you whether you're new to Apache CouchDB or an experienced Apache CouchDB developer.

Bradley Holt

May 13, 2016
Tweet

More Decks by Bradley Holt

Other Decks in Programming

Transcript

  1. HTTP API Apache CouchDB is accessed through an HTTP API

    @BradleyHolt GET / GET /db/doc POST /db DELETE /db/doc PUT /db/doc PUT /db
  2. Shards and Replicas §  q=8 –  Number of shards – 

    One or more shards per node –  Cannot have more nodes than shards §  r=2 –  Read quorum §  w=2 –  Write quorum §  n=3 –  Number of replicas of every document @BradleyHolt CouchDB node1 CouchDB node2 CouchDB node3
  3. What else is new? §  Improved database compaction §  Faster

    index updates §  New _bulk_get endpoint for optimized replication §  View-based filters in _changes feed §  Filter _changes feed with _doc_ids §  _all_docs and _changes will support attachments=true @BradleyHolt
  4. Apache CouchDB 2.0 Sandbox Cluster Try Apache CouchDB 2.0 on

    an IBM Cloudant sandbox cluster @BradleyHolt
  5. http-console $ npm install http-console -g! $ http-console 127.0.0.1:5984! >

    http-console 0.6.3! > Welcome, enter .help if you're lost.! > Connecting to 127.0.0.1 on port 5984.! @BradleyHolt https://github.com/cloudhead/http-console
  6. http-console http://127.0.0.1:5984/> GET /! HTTP/1.1 200 OK! Content-Type: text/plain; charset=utf-8!

    ! {! couchdb: 'Welcome',! version: '9afa6a0',! vendor: { name: 'The Apache Software Foundation' }! } @BradleyHolt https://github.com/cloudhead/http-console
  7. http-console $ http-console https://bradley-holt.cloudant.com! > http-console 0.6.3! > Welcome, enter

    .help if you're lost.! > Connecting to bradley-holt.cloudant.com on port 443.! @BradleyHolt https://github.com/cloudhead/http-console
  8. http-console https://bradley-holt.cloudant.com:443/> GET /! HTTP/1.1 200 OK! Content-Type: application/json! !

    {! couchdb: 'Welcome',! version: '9d28c57',! vendor: {! name: 'IBM Cloudant',! version: '5331',! variant: 'paas'! },! features: [ 'geo' ]! }! @BradleyHolt https://github.com/cloudhead/http-console
  9. Connecting to CouchDB 2.0 $ http-console root:[email protected]:5984 --json! > http-console

    0.6.3! > Welcome, enter .help if you're lost.! > Connecting to 127.0.0.1 on port 5984.! @BradleyHolt
  10. Connecting to IBM Cloudant $ http-console https://bradley-holt:[email protected] --json! > http-console

    0.6.3! > Welcome, enter .help if you're lost.! > Connecting to bradley-holt.cloudant.com on port 443.! @BradleyHolt
  11. PUT a Database /> PUT /kittens! ... ! HTTP/1.1 201

    Created! Content-Type: application/json! Location: http://127.0.0.1/kittens! ! { ok: true }! @BradleyHolt
  12. PUT a Database Again /> PUT /kittens! ... ! HTTP/1.1

    412 Precondition Failed! Content-Type: application/json! ! { error: 'file_exists', reason: 'The database could not be created, the file already exists.' }! @BradleyHolt
  13. POST a Document /kittens> POST /! ... { "_id": "mittens",

    "age_weeks": 10, "weight_kilograms": 0.997 }! HTTP/1.1 201 Created! Content-Type: application/json! Location: http://127.0.0.1/kittens/mittens! ! {! ok: true,! id: 'mittens',! rev: '1-e665a40d9ea9711c983e907f0b0b6e8a'! }! @BradleyHolt
  14. GET All Documents /kittens> GET /_all_docs! HTTP/1.1 200 OK! Content-Type:

    application/json! Etag: "92afa0f309a9fd9f140cd31ff5000b5c"! ! {! total_rows: 1,! offset: 0,! rows: [! {! id: 'mittens',! key: 'mittens',! value: { rev: '1-e665a40d9ea9711c983e907f0b0b6e8a' }! }! ]! }! @BradleyHolt
  15. GET a Document /kittens> GET /mittens! HTTP/1.1 200 OK! Content-Type:

    application/json! Etag: "1-e665a40d9ea9711c983e907f0b0b6e8a"! ! {! _id: 'mittens',! _rev: '1-e665a40d9ea9711c983e907f0b0b6e8a',! age_weeks: 10,! weight_kilograms: 0.997! }! @BradleyHolt
  16. PUT an Attachment /kittens> .headers! Accept: application/json! Content-Type: application/json! Authorization:

    Basic cm9vdDorMi95N3Y2aA==! Host: 127.0.0.1! /kittens> Content-Type: image/gif! @BradleyHolt
  17. PUT an Attachment /kittens> PUT /mittens/photo?rev=1-e665a40d9ea9711c983e907f0b0b6e8a! ... R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=! HTTP/1.1 201

    Created! Content-Type: application/json! Location: http://127.0.0.1/kittens/mittens/photo! ! {! ok: true,! id: 'mittens',! rev: '2-d858e51453a5785bafe517b7eddc5a98'! }! /kittens> Content-Type: application/json! @BradleyHolt
  18. GET an Attachment /kittens> GET /mittens/photo! HTTP/1.1 200 OK! Content-Type:

    image/gif! Etag: "UsqjdPnY6ApD2ENFOglFHg=="! ! R0lGODlhAQABAIAAAP///wAAACwAAAAAAQABAAACAkQBADs=! @BradleyHolt
  19. DELETE a Document /kittens> DELETE /mittens! HTTP/1.1 409 Conflict! Content-Type:

    application/json! ! { error: 'conflict', reason: 'Document update conflict.' }! @BradleyHolt
  20. DELETE a Document /kittens> HEAD /mittens! HTTP/1.1 200 OK! Etag:

    "2-d858e51453a5785bafe517b7eddc5a98"! ! @BradleyHolt
  21. DELETE a Document /kittens> If-Match: "2-d858e51453a5785bafe517b7eddc5a98"! /kittens> DELETE /mittens! HTTP/1.1

    200 OK! Content-Type: application/json! ! {! ok: true,! id: 'mittens',! rev: '3-d0780627ddff7a7f536fe273100cec41'! }! /kittens> If-Match:! @BradleyHolt
  22. Replication /> POST /_replicate! ... { "create_target": true, "source": "https://bradley-holt.cloudant.com/

    kittens", "target": "kittens" }! HTTP/1.1 200 OK! Content-Type: application/json! ! {! ok: true,! session_id: '9f7bd286a0001ece5bf0bf65dd83c5ab',! source_last_seq: '5- g1AAAAFDeJzLYWBgYMlgTmGQT0lKzi9KdUhJMtVLykxPyilN1UvOyS9NScwr0ctLLckBKmRKZEiy___ _f1YiA6oWQ9xakhyAZFI9SFcGcyJzLpDHbplmZmxkaULYBKIdlscCJBkagBTQov2kuA- i8wBEJ9iNTGA3mhoampmnGBA2JQsA1LtoyA',! …! }! @BradleyHolt
  23. Mango /kittens> POST /_index! ... { "index": { "fields": [

    "age_weeks", "weight_kilograms" ] } }! HTTP/1.1 200 OK! Content-Type: application/json! ! {! result: 'created',! id: '_design/e19dde7f518129a966ebe072edc66be88d54e694',! name: 'e19dde7f518129a966ebe072edc66be88d54e694'! }! @BradleyHolt
  24. Mango /kittens> POST /_find! ... { "selector": { "age_weeks": {

    "$gte": 7, "$lte": 10 } }, "fields": [ "_id", "age_weeks" ] }! HTTP/1.1 200 OK! Content-Type: application/json! ! {! docs: [! { _id: 'tiger', age_weeks: 7 },! { _id: 'daisy', age_weeks: 9 },! { _id: 'mittens', age_weeks: 10 }! ]! }! @BradleyHolt
  25. Mango /kittens> POST /_find! ... { "selector": { "age_weeks": {

    "$gte": 0 }, "weight_kilograms": { "$gte": 0.5, "$lte": 1 } }, "fields": [ "_id", "weight_kilograms" ] }! HTTP/1.1 200 OK! Content-Type: application/json! ! {! docs: [! { _id: 'tiger', weight_kilograms: 0.726 },! { _id: 'daisy', weight_kilograms: 0.816 },! { _id: 'mittens', weight_kilograms: 0.997 }! ]! }! @BradleyHolt
  26. Image Credits §  paper by malik, on Flickr <https://flic.kr/p/aZjTXv> § 

    person by Tim Morgan, on Flickr <https://flic.kr/p/7DSF5> §  database by Tim Morgan, on Flickr <https://flic.kr/p/7DUk5> §  gear by Tim Morgan, on Flickr <https://flic.kr/p/7DSF1> §  Mango with section on a white background by bangdoll, on Flickr <https://flic.kr/p/9CBP2h> @BradleyHolt