Mind map
CouchDB
Map content
CouchDB
API
- Server
- can serve as a sanity check to see if CouchDB is running at all. It can also act as a safety guard for libraries that require a certain version of CouchDB
- Exmaple: {"couchdb":"Welcome","version":"0.10.1"}
- Databases
- a bucket that holds “related data.”
- Documents
- central data structure
- Replication
- a mechanism to synchronize databases.
- { "history": [ { "start_last_seq": 0, "missing_found": 2, "docs_read": 2, "end_last_seq": 5, "missing_checked": 2, "docs_written": 2, "doc_write_failures": 0, "end_time": "Sat, 11 Jul 2009 17:36:21 GMT", "start_time": "Sat, 11 Jul 2009 17:36:20 GMT" } ], "source_last_seq": 5, "session_id": "924e75e914392343de89c99d29d06671", "ok": true }
- Server
Design Documents
- a CouchDB document with an id that begins with _design/
- View Functions
- Views are the primary tool used for querying and reporting on CouchDB databases.
- Map Functions
- accept a single document as the argument and (optionally) emit() key/value pairs that are stored in a view.
- Reduce Functions
- take two required arguments of keys and values lists - the result of the related map function - and an optional third value which indicates if rereduce mode is active or not.
- redfun(keys, values[, rereduce])
- Built-Ins Funcs
- _approx_count_distinct
- Aproximates the number of distinct keys in a view index using a variant of the HyperLogLogalgorithm.
- _count
- Counts the number of values in the index with a given key.
- _approx_count_distinct
- Show Functions
- are used to represent documents in various formats, commonly as HTML pages with nice formatting.
- showfun(doc, req)
- function(doc, req){ if (doc) { return "Hello from " + doc._id + "!"; } else { return "Hello, world!"; } }
- function(doc, req){ return { 'json': { 'id': doc['_id'], 'rev': doc['_rev'] } } }
- List Functions
- While Show Functions are used to customize document presentation, List Functions are used for the same purpose, but on View Functions results.
- The following list function formats the view and represents it as a very simple HTML page: function(head, req){ start({ 'headers': { 'Content-Type': 'text/html' } }); send('<html><body><table>'); send('<tr><th>ID</th><th>Key</th><th>Value</th></tr>') while(row = getRow()){ send(''.concat( '<tr>', '<td>' + toJSON(row.id) + '</td>', '<td>' + toJSON(row.key) + '</td>', '<td>' + toJSON(row.value) + '</td>', '</tr>' )); } send('</table></body></html>'); }
- Update Functions
- are functions that clients can request to invoke server-side logic that will create or update a document
- function(doc, req){ if (!doc){ if ('id' in req && req['id']){ // create new document return [{'_id': req['id']}, 'New World'] } // change nothing in database return [null, 'Empty World'] } doc['world'] = 'hello'; doc['edited_by'] = req['userCtx']['name'] return [doc, 'Edited World!'] }
- Filter Functions
- Filter functions mostly act like Show Functions and List Functions: they format, or filter the changes feed.
- special design document functions that allow the changes feed to emit only specific documents that pass filter rules.
- Filter functions must return true if a document passed all the rules.
- Classic
- View
- are the same as classic filters above, with one small difference: they use the mapinstead of the filter function of a view, to filter the changes feed.
- Each time a key-value pair is emitted from the map function, a change is returned. This allows avoiding filter functions that mostly do the same work as views.
- To use them just pass filter=_view and view=designdoc/viewname as request parameters to the changes feed GET /somedatabase/_changes?filter=_view&view=dname/viewname HTTP/1.1:
- Validation Functions
- can be used to prevent invalid or unauthorized document update requests from being stored.
- validatefun(newDoc, oldDoc, userCtx, secObj) newDoc – New version of document that will be stored. oldDoc – Previous version of document that is already stored.userCtx – User Context ObjectsecObj – Security Object
JSON Data Structures
- Database Documents
- total_rows
- offset
- update_seq
- rows
- CouchDB Document
- Design Document
- views
- viewname
- map
- reduce
- Request Object
- body
- cookie
- form
- headers
- id
- info
- method
- path
- peer
- query
- requested_path
- raw_path
- secObj
- uuid
- Generic Fields
- _id
- _rev
- userCtx
- secObj
- Database Documents
Information
- Description
- Mind Map on CouchDB, created by C Bax on 25/09/2018.
- Created by
- C Bax
- Views
- 0
- Rating