diff options
author | Dave Cottlehuber <dch@apache.org> | 2012-12-03 13:36:58 +0100 |
---|---|---|
committer | Dave Cottlehuber <dch@apache.org> | 2012-12-11 14:10:52 +0100 |
commit | ffca957478b13ac9a68cdb78a255b2ea8d8f471d (patch) | |
tree | ce1ee163831ff0af3299c72b4e3e874c9f5614c9 | |
parent | d977eb7ec52bc13dca7b4f530cb51f42df0f6224 (diff) | |
download | couchdb-ffca957478b13ac9a68cdb78a255b2ea8d8f471d.tar.gz |
import Couchbase docs
git clone git://github.com/janl/couchdb-docs.git
cd couchdb-docs
rm -rf DocKit Makefile Makefile.bootstrap README.md common couchdb-manual-1.1 couchdb-release-1.1 metadocs
git checkout 9fc95b422060d020ba25f559e893fc7fb98c9a15 -- 'couchdb-manual-1.1/*.xml' 'couchdb-release-1.1/*.xml'
tar cvzf couchdb-docs.tar.gz couchdb-manual-1.1 couchdb-release-1.1
31 files changed, 28614 insertions, 0 deletions
diff --git a/share/docs/couchdb-manual-1.1/couchdb-api-auth-metasrc.xml b/share/docs/couchdb-manual-1.1/couchdb-api-auth-metasrc.xml new file mode 100644 index 000000000..417500a7a --- /dev/null +++ b/share/docs/couchdb-manual-1.1/couchdb-api-auth-metasrc.xml @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-api-auth"> + + <title>CouchDB API Server Authentication Methods</title> + + <para> + The CouchDB Authentication methods provide an interface for + obtaining session and authorization data. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <para role="meta" id="table-couchdb-api-auth-summary"> + <remark role="title">Authentication API Calls</remark> + + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="summarytable"/> + + <remark role="filter_class" condition="auth"/> + + <remark role="version" condition="inherit"/> + + <remark role="idprefix" condition="couchdb-api-auth"/> + </para> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/couchdb-api-config-metasrc.xml b/share/docs/couchdb-manual-1.1/couchdb-api-config-metasrc.xml new file mode 100644 index 000000000..aa1ac2777 --- /dev/null +++ b/share/docs/couchdb-manual-1.1/couchdb-api-config-metasrc.xml @@ -0,0 +1,359 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-api-config"> + + <title>CouchDB API Server Configuration Methods</title> + + <para> + The CouchDB API Server Configuration Methods provide an interface to + query and update the various configuration values within a running + CouchDB instance. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <para role="meta" id="table-couchdb-api-config-summary"> + <remark role="title">Configuration API Calls</remark> + + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="summarytable"/> + + <remark role="filter_class" condition="config"/> + + <remark role="version" condition="inherit"/> + + <remark role="idprefix" condition="couchdb-api-config"/> + </para> + + <section id="couchdb-api-config_config_get"> + + <title><literal>GET /_config</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="config"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Returns the entire CouchDB server configuration as a JSON + structure. The structure is organized by different configuration + sections, with individual values. + </para> + + <para> + For example, to get the configuration for a server: + </para> + +<programlisting> +GET http://couchdb:5984/_config +Accept: application/json +</programlisting> + + <para> + The response is the JSON structure: + </para> + +<programlisting> +<![CDATA[{ + "query_server_config" : { + "reduce_limit" : "true" + }, + "couchdb" : { + "os_process_timeout" : "5000", + "max_attachment_chunk_size" : "4294967296", + "max_document_size" : "4294967296", + "uri_file" : "/var/lib/couchdb/couch.uri", + "max_dbs_open" : "100", + "view_index_dir" : "/var/lib/couchdb", + "util_driver_dir" : "/usr/lib64/couchdb/erlang/lib/couch-1.0.1/priv/lib", + "database_dir" : "/var/lib/couchdb", + "delayed_commits" : "true" + }, + "attachments" : { + "compressible_types" : "text/*, application/javascript, application/json, application/xml", + "compression_level" : "8" + }, + "uuids" : { + "algorithm" : "utc_random" + }, + "daemons" : { + "view_manager" : "{couch_view, start_link, []}", + "auth_cache" : "{couch_auth_cache, start_link, []}", + "uuids" : "{couch_uuids, start, []}", + "stats_aggregator" : "{couch_stats_aggregator, start, []}", + "query_servers" : "{couch_query_servers, start_link, []}", + "httpd" : "{couch_httpd, start_link, []}", + "stats_collector" : "{couch_stats_collector, start, []}", + "db_update_notifier" : "{couch_db_update_notifier_sup, start_link, []}", + "external_manager" : "{couch_external_manager, start_link, []}" + }, + "stats" : { + "samples" : "[0, 60, 300, 900]", + "rate" : "1000" + }, + "httpd" : { + "vhost_global_handlers" : "_utils, _uuids, _session, _oauth, _users", + "secure_rewrites" : "true", + "authentication_handlers" : "{couch_httpd_oauth, oauth_authentication_handler}, + {couch_httpd_auth, cookie_authentication_handler}, + {couch_httpd_auth, default_authentication_handler}", + "port" : "5984", + "default_handler" : "{couch_httpd_db, handle_request}", + "allow_jsonp" : "false", + "bind_address" : "192.168.0.2", + "max_connections" : "2048" + }, + "query_servers" : { + "javascript" : "/usr/bin/couchjs /usr/share/couchdb/server/main.js" + }, + "couch_httpd_auth" : { + "authentication_db" : "_users", + "require_valid_user" : "false", + "authentication_redirect" : "/_utils/session.html", + "timeout" : "600", + "auth_cache_size" : "50" + }, + "httpd_db_handlers" : { + "_design" : "{couch_httpd_db, handle_design_req}", + "_compact" : "{couch_httpd_db, handle_compact_req}", + "_view_cleanup" : "{couch_httpd_db, handle_view_cleanup_req}", + "_temp_view" : "{couch_httpd_view, handle_temp_view_req}", + "_changes" : "{couch_httpd_db, handle_changes_req}" + }, + "replicator" : { + "max_http_sessions" : "10", + "max_http_pipeline_size" : "10" + }, + "log" : { + "include_sasl" : "true", + "level" : "info", + "file" : "/var/log/couchdb/couch.log" + }, + "httpd_design_handlers" : { + "_update" : "{couch_httpd_show, handle_doc_update_req}", + "_show" : "{couch_httpd_show, handle_doc_show_req}", + "_info" : "{couch_httpd_db, handle_design_info_req}", + "_list" : "{couch_httpd_show, handle_view_list_req}", + "_view" : "{couch_httpd_view, handle_view_req}", + "_rewrite" : "{couch_httpd_rewrite, handle_rewrite_req}" + }, + "httpd_global_handlers" : { + "_replicate" : "{couch_httpd_misc_handlers, handle_replicate_req}", + "/" : "{couch_httpd_misc_handlers, handle_welcome_req, <<\"Welcome\">>}", + "_config" : "{couch_httpd_misc_handlers, handle_config_req}", + "_utils" : "{couch_httpd_misc_handlers, handle_utils_dir_req, \"/usr/share/couchdb/www\"}", + "_active_tasks" : "{couch_httpd_misc_handlers, handle_task_status_req}", + "_session" : "{couch_httpd_auth, handle_session_req}", + "_log" : "{couch_httpd_misc_handlers, handle_log_req}", + "favicon.ico" : "{couch_httpd_misc_handlers, handle_favicon_req, \"/usr/share/couchdb/www\"}", + "_all_dbs" : "{couch_httpd_misc_handlers, handle_all_dbs_req}", + "_oauth" : "{couch_httpd_oauth, handle_oauth_req}", + "_restart" : "{couch_httpd_misc_handlers, handle_restart_req}", + "_uuids" : "{couch_httpd_misc_handlers, handle_uuids_req}", + "_stats" : "{couch_httpd_stats_handlers, handle_stats_req}" + } +}]]> + </programlisting> + + </section> + + <section id="couchdb-api-config_config-section_get"> + + <title><literal>GET /_config/section</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="config-section"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Gets the configuration structure for a single section. For + example, to retrieve the CouchDB configuration section values: + </para> + +<programlisting> +GET http://couchdb:5984/_config/couchdb +Accept: application/json +</programlisting> + + <para> + The returned JSON contains just the configuration values for this + section: + </para> + +<programlisting> +{ + "os_process_timeout" : "5000", + "max_attachment_chunk_size" : "4294967296", + "max_document_size" : "4294967296", + "uri_file" : "/var/lib/couchdb/couch.uri", + "max_dbs_open" : "100", + "view_index_dir" : "/var/lib/couchdb", + "util_driver_dir" : "/usr/lib64/couchdb/erlang/lib/couch-1.0.1/priv/lib", + "database_dir" : "/var/lib/couchdb", + "delayed_commits" : "true" +} +</programlisting> + + </section> + + <section id="couchdb-api-config_config-section-key_get"> + + <title><literal>GET /_config/section/key</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="config-section-key"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Gets a single configuration value from within a specific + configuration section. For example, to obtain the current log + level: + </para> + +<programlisting> +GET http://couchdb:5984/_config/log/level +Accept: application/json +</programlisting> + + <para> + Returns the string of the log level: + </para> + +<programlisting> +"info" +</programlisting> + + <note> + <para> + The returned value will be the JSON of the value, which may be a + string or numeric value, or an array or object. Some client + environments may not parse simple strings or numeric values as + valid JSON. + </para> + </note> + + </section> + + <section id="couchdb-api-config_config-section-key_put"> + + <title><literal>PUT /_config/section/key</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="config-section-key"/> + + <remark role="method" condition="PUT"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Updates a configuration value. The new value should be supplied in + the request body in the corresponding JSON format. For example, if + you are setting a string value, you must supply a valid JSON + string. + </para> + + <para> + For example, to set the function used to generate UUIDs by the + <literal>GET /_uuids</literal> API call to use the + <literal>utc_random</literal> generator: + </para> + +<programlisting> +PUT http://couchdb:5984/_config/uuids/algorithm +Content-Type: application/json + +"utc_random" +</programlisting> + + <para> + The return value will be empty, with the response code indicating + the success or failure of the configuration setting. + </para> + + </section> + + <section id="couchdb-api-config_config-section-key_delete"> + + <title><literal>DELETE /_config/section/key</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="config-section-key"/> + + <remark role="method" condition="DELETE"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Deletes a configuration value. The returned JSON will be the value + of the configuration parameter before it was deleted. For example, + to delete the UUID parameter: + </para> + +<programlisting> +DELETE http://couchdb:5984/_config/uuids/algorithm +Content-Type: application/json +</programlisting> + + <para> + The returned value is the last configured UUID function: + </para> + +<programlisting> +"random" +</programlisting> + + </section> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/couchdb-api-db-metasrc.xml b/share/docs/couchdb-manual-1.1/couchdb-api-db-metasrc.xml new file mode 100644 index 000000000..0b3084aa7 --- /dev/null +++ b/share/docs/couchdb-manual-1.1/couchdb-api-db-metasrc.xml @@ -0,0 +1,1828 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-api-db"> + + <title>CouchDB API Server Database Methods</title> + + <para> + The Database methods provide an interface to an entire database + withing CouchDB. These are database, rather than document, level + requests. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <para role="meta" id="table-couchdb-api-db-summary"> + <remark role="title">Database API Calls</remark> + + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="summarytable"/> + + <remark role="filter_class" condition="db"/> + + <remark role="version" condition="inherit"/> + + <remark role="idprefix" condition="couchdb-api-db"/> + </para> + + <para> + For all the database methods, the database name within the URL path + should be the database name that you wish to perform the operation + on. For example, to obtain the meta information for the database + <literal>recipes</literal>, you would use the HTTP request: + </para> + +<programlisting> +GET /recipes +</programlisting> + + <para> + For clarity, the form below is used in the URL paths: + </para> + +<programlisting> +GET /db +</programlisting> + + <para> + Where <literal>db</literal> is the name of any database. + </para> + + <section id="couchdb-api-db_db_get"> + + <title><literal>GET /db</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Gets information about the specified database. For example, to + retrieve the information for the database + <literal>recipe</literal>: + </para> + +<programlisting role="httprequest"> +GET http://couchdb:5984/recipes +Accept: application/json +</programlisting> + + <para> + The JSON response contains meta information about the database. A + sample of the JSON returned for an empty database is provided + below: + </para> + +<programlisting role="httpresponse"> +{ + "compact_running" : false, + "committed_update_seq" : 375048, + "disk_format_version" : 5, + "disk_size" : 33153123, + "doc_count" : 18386, + "doc_del_count" : 0, + "db_name" : "recipes", + "instance_start_time" : "1290700340925570", + "purge_seq" : 10, + "update_seq" : 375048 +} + </programlisting> + + <para> + The elements of the returned structure are shown in the table + below: + </para> + + <para role="meta" id="table-couchdb-api-db-json-db-info"> + <remark role="type" condition="json"/> + + <remark role="src" condition="json"/> + + <remark role="output" condition="itemtable"/> + + <remark role="itemid" condition="db-info"/> + + <remark role="version" condition="inherit"/> + </para> + + </section> + + <section id="couchdb-api-db_db_put"> + + <title><literal>PUT /db</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db"/> + + <remark role="method" condition="PUT"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Creates a new database. The database name must be composed of one + or more of the following characters: + </para> + + <itemizedlist> + + <listitem> + <para> + Lowercase characters (<literal>a-z</literal>) + </para> + </listitem> + + <listitem> + <para> + Name must begin with a lowercase letter + </para> + </listitem> + + <listitem> + <para> + Digits (<literal>0-9</literal>) + </para> + </listitem> + + <listitem> + <para> + Any of the characters <literal>_</literal>, + <literal>$</literal>, <literal>(</literal>, + <literal>)</literal>, <literal>+</literal>, + <literal>-</literal>, and <literal>/</literal>. + </para> + </listitem> + + </itemizedlist> + + <para> + Trying to create a database that does not meet these requirements + will return an error quoting these restrictions. + </para> + + <para> + To create the database <literal>recipes</literal>: + </para> + +<programlisting> +PUT http://couchdb:5984/recipes +Content-Type: application/json +</programlisting> + + <para> + The returned content contains the JSON status: + </para> + +<programlisting> +{ + "ok" : true +} +</programlisting> + + <para> + Anything should be treated as an error, and the problem should be + taken form the HTTP response code. + </para> + + </section> + + <section id="couchdb-api-db_db_delete"> + + <title><literal>DELETE /db</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db"/> + + <remark role="method" condition="DELETE"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Deletes the specified database, and all the documents and + attachments contained within it. + </para> + + <para> + To delete the database <literal>recipes</literal> you would send + the request: + </para> + +<programlisting> +DELETE http://couchdb:5984/recipes +Content-Type: application/json +</programlisting> + + <para> + If successful, the returned JSON will indicate success + </para> + +<programlisting> +{ + "ok" : true +} +</programlisting> + + </section> + + <section id="couchdb-api-db_db-changes_get"> + + <title><literal>GET /db/_changes</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-changes"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Obtains a list of the changes made to the database. This can be + used to monitor for update and modifications to the database for + post processing or synchronization. There are three different + types of supported changes feeds, poll, longpoll, and continuous. + All requests are poll requests by default. You can select any feed + type explicitly using the <literal>feed</literal> query argument. + </para> + + <para> + <itemizedlist> + + <listitem> + <para> + <emphasis role="bold">Poll</emphasis> + </para> + + <para> + With polling you can request the changes that have occured + since a specific sequence number. This returns the JSON + structure containing the changed document information. When + you perform a poll change request, only the changes since + the specific sequence number are returned. For example, the + query + </para> + +<programlisting> +DELETE http://couchdb:5984/recipes/_changes +Content-Type: application/json +</programlisting> + + <para> + Will get all of the changes in the database. You can request + a starting point using the <literal>since</literal> query + argument and specifying the sequence number. You will need + to record the latest sequence number in your client and then + use this when making another request as the new value to the + <literal>since</literal> parameter. + </para> + </listitem> + + <listitem> + <para> + <emphasis role="bold">Longpoll</emphasis> + </para> + + <para> + With long polling the request to the server will remain open + until a change is made on the database, when the changes + will be reported, and then the connection will close. The + long poll is useful when you want to monitor for changes for + a specific purpose without wanting to monitoring + continuously for changes. + </para> + + <para> + Because the wait for a change can be significant you can set + a timeout before the connection is automatically closed (the + <literal>timeout</literal> argument). You can also set a + heartbeat interval (using the <literal>heartbeat</literal> + query argument), which sends a newline to keep the + connection open. + </para> + </listitem> + + <listitem> + <para> + <emphasis role="bold">Continuous</emphasis> + </para> + + <para> + Continuous sends all new changes back to the client + immediately, without closing the connection. In continuous + mode the format of the changes is slightly different to + accommodate the continuous nature while ensuring that the + JSON output is still valid for each change notification. + </para> + + <para> + As with the longpoll feed type you can set both the timeout + and heartbeat intervals to ensure that the connection is + kept open for new changesand updates. + </para> + </listitem> + + </itemizedlist> + </para> + + <para> + The return structure for <literal>normal</literal> and + <literal>longpoll</literal> modes is a JSON array of changes + objects, and the last update sequence number. The structure is + described in the following table. + </para> + + <para role="meta" id="table-couchdb-api-db_db-json-changes"> + <remark role="type" condition="json"/> + + <remark role="src" condition="json"/> + + <remark role="output" condition="itemtable"/> + + <remark role="itemid" condition="changes"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + The return format for <literal>continuous</literal> mode the + server sends a CRLF (carriage-return, linefeed) delimited line for + each change. Each line contains the + <link linkend="table-couchdb-api-db_db-json-changes">JSON + object</link>. + </para> + + <para> + You can also request the full contents of each document change + (instead of just the change notification) by using the + <literal>include_docs</literal> parameter. + </para> + + <section id="couchdb-api-db_db-changes_get-filters"> + + <title>Filtering</title> + + <para> + You can filter the contents of the changes feed in a number of + ways. The most basic way is to specify one or more document IDs + to the query. This causes the returned structure value to only + contain changes for the specified IDs. Note that the value of + this query argument should be a JSON formatted array. + </para> + + <para> + You can also filter the <literal>_changes</literal> feed by + defining a filter function within a design document. The + specification for the filter is the same as for replication + filters. You specify the name of the filter function to the + <literal>filter</literal> parameter, specifying the design + document name and filter name. For example: + </para> + +<programlisting> +GET /db/_changes?filter=design_doc/filtername +</programlisting> + + <para> + The <literal>_changes</literal> feed can be used to watch + changes to specific document ID's or the list of + <literal>_design</literal> documents in a database. If the + <literal>filters</literal> parameter is set to + <literal>_doc_ids</literal> a list of doc IDs can be passed in + the <option>doc_ids</option> parameter as a JSON array. + </para> + + <para> + For more information, see + <xref linkend="couchdb-single-changes-filters"/>. + </para> + + </section> + + </section> + + <section id="couchdb-api-db_db-compact_post"> + + <title><literal>POST /db/_compact</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-compact"/> + + <remark role="method" condition="POST"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Request compaction of the specified database. Compaction + compresses the disk database file by performing the following + operations: + </para> + + <itemizedlist> + + <listitem> + <para> + Writes a new version of the database file, removing any unused + sections from the new version during write. Because a new file + is temporary created for this purpose, you will need twice the + current storage space of the specified database in order for + the compaction routine to complete. + </para> + </listitem> + + <listitem> + <para> + Removes old revisions of documents from the database, up to + the per-database limit specified by the + <literal>_revs_limit</literal> database parameter. See + <xref linkend="couchdb-api-db_db_get"/> . + </para> + </listitem> + + </itemizedlist> + + <para> + Compaction can only be requested on an individual database; you + cannot compact all the databases for a CouchDB instance. The + compaction process runs as a background process. + </para> + + <para> + You can determine if the compaction process is operating on a + database by obtaining the database meta information, the + <literal>compact_running</literal> value of the returned database + structure will be set to true. See + <xref linkend="couchdb-api-db_db_get"/> . + </para> + + <para> + You can also obtain a list of running processes to determine + whether compaction is currently running. See + <xref linkend="couchdb-api-misc_active-tasks_get"/>. + </para> + + </section> + + <section id="couchdb-api-db_db-compact-design-doc_post"> + + <title><literal>POST /db/_compact/design-doc</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-compact-design-doc"/> + + <remark role="method" condition="POST"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Compacts the view indexes associated with the specified design + document. You can use this in place of the full database + compaction if you know a specific set of view indexes have been + affected by a recent database change. + </para> + + <para> + For example, to compact the views associated with the + <literal>recipes</literal> design document: + </para> + +<programlisting> +POST http://couchdb:5984/recipes/_compact/recipes +Content-Type: application/json +</programlisting> + + <para> + CouchDB will immediately return with a status indicating that the + compaction request has been received (HTTP status code 202): + </para> + +<programlisting> +{ + "ok" : true +} + </programlisting> + + </section> + + <section id="couchdb-api-db_db-view-cleanup_post"> + + <title><literal>POST /db/_view_cleanup</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-view-cleanup"/> + + <remark role="method" condition="POST"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Cleans up the cached view output on disk for a given view. For + example: + </para> + +<programlisting> +POST http://couchdb:5984/recipes/_view_cleanup +Content-Type: application/json +</programlisting> + + <para> + If the request is successful, a basic status message us returned: + </para> + +<programlisting> +{ + "ok" : true +} + </programlisting> + + </section> + + <section id="couchdb-api-db_db-ensure-full-commit_post"> + + <title><literal>POST /db/_ensure_full_commit</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-ensure-full-commit"/> + + <remark role="method" condition="POST"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Commits any recent changes to the specified database to disk. You + should call this if you want to ensure that recent changes have + been written. For example, to commit all the changes to disk for + the database <literal>recipes</literal> you would use: + </para> + +<programlisting> +POST http://couchdb:5984/recipes/_ensure_full_commit +Content-Type: application/json +</programlisting> + + <para> + This returns a status message, containing the success message and + the timestamp for when the CouchDB instance was started: + </para> + +<programlisting> +{ + "ok" : true, + "instance_start_time" : "1288186189373361" +} +</programlisting> + +<!-- <para>You can also optionally commit to disk all the updates up to a + specified update sequence ID by using the <literal>seq</literal> + argument to the request. The value should be the sequence ID returned + when creating or updating a document:</para> + --> + + </section> + + <section id="couchdb-api-db_db-bulk-docs_post"> + + <title><literal>POST /db/_bulk_docs</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-bulk-docs"/> + + <remark role="method" condition="POST"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + The bulk document API allows you to create and update multiple + documents at the same time within a single request. The basic + operation is similar to creating or updating a single document, + except that you batch the document structure and information and . + When creating new documents the document ID is optional. For + updating existing documents, you must provide the document ID, + revision information, and new document values. + </para> + + <para> + For both inserts and updates the basic structure of the JSON is + the same: + </para> + + <para role="meta" id="table-couchdb-api-db_db-bulk-docs-json"> + <remark role="type" condition="json"/> + + <remark role="src" condition="json"/> + + <remark role="output" condition="itemtable"/> + + <remark role="itemid" condition="bulkdocs"/> + + <remark role="version" condition="inherit"/> + </para> + + <section id="couchdb-api-db_db-bulk-docs_post-insert"> + + <title>Inserting Documents in Bulk</title> + + <para> + To insert documents in bulk into a database you need to supply a + JSON structure with the array of documents that you want to add + to the database. Using this method you can either include a + document ID, or allow the document ID to be automatically + generated. + </para> + + <para> + For example, the following inserts three new documents, two with + the supplied document IDs, and one which will have a document ID + generated: + </para> + +<programlisting> +{ + "docs" : [ + { + "_id" : "FishStew", + "servings" : 4, + "subtitle" : "Delicious with fresh bread", + "title" : "Fish Stew" + }, + { + "_id" : "LambStew", + "servings" : 6, + "subtitle" : "Delicious with scone topping", + "title" : "Lamb Stew" + }, + { + "servings" : 8, + "subtitle" : "Delicious with suet dumplings", + "title" : "Beef Stew" + }, + ] +} + </programlisting> + + <para> + The return type from a bulk insertion will be 201, with the + content of the returned structure indicating specific success or + otherwise messages on a per-document basis. + </para> + + <para> + The return structure from the example above contains a list of + the documents created, here with the combination and their + revision IDs: + </para> + +<programlisting> +POST http://couchdb:5984/recipes/_bulk_docs +Content-Type: application/json + +[ + { + "id" : "FishStew", + "rev" : "1-9c65296036141e575d32ba9c034dd3ee", + }, + { + "id" : "LambStew", + "rev" : "1-34c318924a8f327223eed702ddfdc66d", + }, + { + "id" : "7f7638c86173eb440b8890839ff35433", + "rev" : "1-857c7cbeb6c8dd1dd34a0c73e8da3c44", + } +] + </programlisting> + + <para> + The content and structure of the returned JSON will depend on + the transaction semantics being used for the bulk update; see + <xref + linkend="couchdb-api-db_db-bulk-docs_post-commit"/> + for more information. Conflicts and validation errors when + updating documents in bulk must be handled separately; see + <xref + linkend="couchdb-api-db_db-bulk-docs_post-errors"/>. + </para> + + </section> + + <section id="couchdb-api-db_db-bulk-docs_post-update"> + + <title>Updating Documents in Bulk</title> + + <para> + The bulk document update procedure is similar to the insertion + procedure, except that you must specify the document ID and + current revision for every document in the bulk update JSON + string. + </para> + + <para> + For example, you could send the following request: + </para> + +<programlisting> +POST http://couchdb:5984/recipes/_bulk_docs +Content-Type: application/json + +{ + "docs" : [ + { + "_id" : "FishStew", + "_rev" : "1-9c65296036141e575d32ba9c034dd3ee", + "servings" : 4, + "subtitle" : "Delicious with freshly baked bread", + "title" : "Fish Stew" + }, + { + "_id" : "LambStew", + "_rev" : "1-34c318924a8f327223eed702ddfdc66d", + "servings" : 6, + "subtitle" : "Serve with a wholemeal scone topping", + "title" : "Lamb Stew" + }, + { + "_id" : "7f7638c86173eb440b8890839ff35433" + "_rev" : "1-857c7cbeb6c8dd1dd34a0c73e8da3c44", + "servings" : 8, + "subtitle" : "Hand-made dumplings make a great accompaniment", + "title" : "Beef Stew" + } + ] +} +</programlisting> + + <para> + The return structure is the JSON of the updated documents, with + the new revision and ID information: + </para> + +<programlisting> +[ + { + "id" : "FishStew", + "rev" : "2-e7af4c4e9981d960ecf78605d79b06d1" + }, + { + "id" : "LambStew", + "rev" : "2-0786321986194c92dd3b57dfbfc741ce" + }, + { + "id" : "7f7638c86173eb440b8890839ff35433", + "rev" : "2-bdd3bf3563bee516b96885a66c743f8e" + } +] +</programlisting> + + <para> + You can optionally delete documents during a bulk update by + adding the <literal>_deleted</literal> field with a value of + <literal>true</literal> to each docment ID/revision combination + within the submitted JSON structure. + </para> + + <para> + The return type from a bulk insertion will be 201, with the + content of the returned structure indicating specific success or + otherwise messages on a per-document basis. + </para> + + <para> + The content and structure of the returned JSON will depend on + the transaction semantics being used for the bulk update; see + <xref + linkend="couchdb-api-db_db-bulk-docs_post-commit"/> + for more information. Conflicts and validation errors when + updating documents in bulk must be handled separately; see + <xref + linkend="couchdb-api-db_db-bulk-docs_post-errors"/>. + </para> + + </section> + + <section id="couchdb-api-db_db-bulk-docs_post-commit"> + + <title>Bulk Documents Transaction Semantics</title> + + <para> + CouchDB supports two different modes for updating (or inserting) + documents using the bulk documentation system. Each mode affects + both the state of the documents in the event of system failure, + and the level of conflict checking performed on each document. + The two modes are: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal>non-atomic</literal> + </para> + + <para> + The default mode is non-atomic, that is, CouchDB will only + guarantee that some of the documents will be saved when you + send the request. The response will contain the list of + documents successfully inserted or updated during the + process. In the event of a crash, some of the documents may + have been successfully saved, and some will have been lost. + </para> + + <para> + In this mode, the response structure will indicate whether + the document was updated by supplying the new + <literal>_rev</literal> parameter indicating a new document + revision was created. If the update failed, then you will + get an <literal>error</literal> of type + <literal>conflict</literal>. For example: + </para> + +<programlisting> +[ + { + "id" : "FishStew", + "error" : "conflict", + "reason" : "Document update conflict." + }, + { + "id" : "LambStew", + "error" : "conflict", + "reason" : "Document update conflict." + }, + { + "id" : "7f7638c86173eb440b8890839ff35433", + "error" : "conflict", + "reason" : "Document update conflict." + } +] + </programlisting> + + <para> + In this case no new revision has been created and you will + need to submit the document update, with the correct + revision tag, to update the document. + </para> + </listitem> + + <listitem> + <para> + <literal>all-or-nothing</literal> + </para> + + <para> + In all-or-nothing mode, either all documents are written to + the database, or no documents are written to the database, + in the event of a system failure during commit. + </para> + + <para> + In addition, the per-document conflict checking is not + performed. Instead a new revision of the document is + created, even if the new revision is in conflict with the + current revision in the database. The returned structure + contains the list of documents with new revisions: + </para> + +<programlisting> +[ + { + "id" : "FishStew", + "rev" : "2-e7af4c4e9981d960ecf78605d79b06d1" + }, + { + "id" : "LambStew", + "rev" : "2-0786321986194c92dd3b57dfbfc741ce" + }, + { + "id" : "7f7638c86173eb440b8890839ff35433", + "rev" : "2-bdd3bf3563bee516b96885a66c743f8e" + } +] +</programlisting> + + <para> + When updating documents using this mode the revision of a + document included in views will be arbitrary. You can check + the conflict status for a document by using the + <literal>conflicts=true</literal> query argument when + accessing the view. Conflicts should be handled individually + to ensure the consistency of your database. + </para> + +<!-- TODO: Add the forward reference to conflict resolution --> + + <para> + To use this mode, you must include the + <literal>all_or_nothing</literal> field (set to true) within + the main body of the JSON of the request. + </para> + </listitem> + + </itemizedlist> + + <para> + The effects of different database operations on the different + modes are summarized in the table below: + </para> + + <table id="table-couchdb-api-db_db-bulk-docs_post-commit"> + <title>Conflicts on Bulk Inserts</title> + <tgroup cols="4"> + <thead> + <row> + <entry> + Transaction Mode + </entry> + <entry> + Transaction + </entry> + <entry> + Cause + </entry> + <entry> + Resolution + </entry> + </row> + </thead> + <tbody> + <row> + <entry> + Non-atomic + </entry> + <entry> + Insert + </entry> + <entry> + Requested document ID already exists + </entry> + <entry> + Resubmit with different document ID, or update the + existing document + </entry> + </row> + <row> + <entry> + Non-atomic + </entry> + <entry> + Update + </entry> + <entry> + Revision missing or incorrect + </entry> + <entry> + Resubmit with correct revision + </entry> + </row> + <row> + <entry> + All-or-nothing + </entry> + <entry> + Insert + </entry> + <entry> + Additional revision inserted + </entry> + <entry> + Resolve conflicted revisions + </entry> + </row> + <row> + <entry> + All-or-nothing + </entry> + <entry> + Update + </entry> + <entry> + Additional revision inserted + </entry> + <entry> + Resolve conflicted revisions + </entry> + </row> + </tbody> + </tgroup> + </table> + + <para> + Replication of documents is independent of the type of insert or + update. The documents and revisions created during a bulk insert + or update are replicated in the same way as any other document. + This can mean that if you make use of the all-or-nothing mode + the exact list of documents, revisions (and their conflict + state) may or may not be replicated to other databases + correctly. + </para> + + </section> + + <section id="couchdb-api-db_db-bulk-docs_post-errors"> + + <title>Bulk Document Validation and Conflict Errors</title> + + <para> + The JSON returned by the <literal>_bulk_docs</literal> operation + consists of an array of JSON structures, one for each document + in the original submission. The returned JSON structure should + be examined to ensure that all of the documents submitted in the + original request were successfully added to the database. + </para> + + <para> + The exact structure of the returned information is shown in + <xref + linkend="table-couchdb-api-db_db-bulk-docs-return-json"/>. + </para> + + <para role="meta" id="table-couchdb-api-db_db-bulk-docs-return-json"> + <remark role="type" condition="json"/> + + <remark role="src" condition="json"/> + + <remark role="output" condition="itemtable"/> + + <remark role="itemid" condition="bulkdocsreturn"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + When a document (or document revision) is not correctly comitted + to the database because of an error, you should check the + <literal>error</literal> field to determine error type and + course of action. Errors will be one of the following type: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal>conflict</literal> + </para> + + <para> + The document as submitted is in conflict. If you used the + default bulk transaction mode then the new revision will not + have been created and you will need to re-submit the + document to the database. If you used + <literal>all-or-nothing</literal> mode then you will need to + manually resolve the conflicted revisions of the document. + </para> + + <para> + Conflict resolution of documents added using the bulk docs + interface is identical to the resolution procedures used + when resolving conflict errors during replication. + </para> + +<!-- TODO: Add a reference/link to the conflict/replication docs --> + </listitem> + + <listitem> + <para> + <literal>forbidden</literal> + </para> + + <para> + Entries with this error type indicate that the validation + routine applied to the document during submission has + returned an error. + </para> + + <para> + For example, if your validation routine includes the + following: + </para> + +<programlisting> throw({forbidden: 'invalid recipe ingredient'});</programlisting> + + <para> + The error returned will be: + </para> + +<programlisting> +{ + "id" : "7f7638c86173eb440b8890839ff35433", + "error" : "forbidden", + "reason" : "invalid recipe ingredient" +} + </programlisting> + + <para> + For more information, see + <xref linkend="couchdb-api-functional-validation"/>. + </para> + </listitem> + + </itemizedlist> + + </section> + + </section> + + <section id="couchdb-api-db_db-temp-view_post"> + + <title><literal>POST /db/_temp_view</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-temp-view"/> + + <remark role="method" condition="POST"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Creates (and executes) a temporary view based on the view function + supplied in the JSON request. For example: + </para> + +<programlisting> +POST http://couchdb:5984/recipes/_temp_view +Content-Type: application/json + +{ + "map" : "function(doc) { if (doc.value > 9995) { emit(null, doc.value); } }" +} +</programlisting> + + <para> + The resulting JSON response is the result from the execution of + the temporary view: + </para> + +<programlisting> +{ + "total_rows" : 3, + "rows" : [ + { + "value" : 9998.41913029012, + "id" : "05361cc6aa42033878acc1bacb1f39c2", + "key" : null + }, + { + "value" : 9998.94149934853, + "id" : "1f443f471e5929dd7b252417625ed170", + "key" : null + }, + { + "value" : 9998.01511339154, + "id" : "1f443f471e5929dd7b252417629c102b", + "key" : null + } + ], + "offset" : 0 +} +</programlisting> + + <para> + The arguments also available to standard view requests also apply + to temporary views, but the execution of the view may take some + time as it relies on being executed at the time of the request. In + addition to the time taken, they are also computationally very + expensive to produce. You should use a defined view if you want to + achieve the best performance. + </para> + + <para> + For more information, see + <xref linkend="couchdb-api-functional-views"/>. + </para> + + </section> + + <section id="couchdb-api-db_db-purge_post"> + + <title><literal>POST /db/_purge</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-purge"/> + + <remark role="method" condition="POST"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + A database purge permanently removes the references to deleted + documents from the database. Deleting a document within CouchDB + does not actually remove the documen from the database, instead, + the document is marked as a deleted (and a new revision is + created). This is to ensure that deleted documents are replicated + to other databases as having been deleted. This also means that + you can check the status of a document and identify that the + document has been deleted. + </para> + + <para> + The purge operation removes the refernces to the deleted documents + from the database. The purging of old documents is not replicated + to other databases. If you are replicating between databases and + have deleted a large number of documents you should run purge on + each database. + </para> + + <note> + <para> + Purging documents does not remove the space used by them on + disk. To reclaim disk space, you should run a database compact + (see <xref + linkend="couchdb-api-db_db-compact_post"/>, and + compact views (see + <xref + linkend="couchdb-api-db_db-compact-design-doc_post"/>). + </para> + </note> + + <para> + To perform a purge operation you must send a request including the + JSON of the document IDs that you want to purge. For example: + </para> + +<programlisting> +POST http://couchdb:5984/recipes/_purge +Content-Type: application/json + +{ + "FishStew" : [ + "17-b3eb5ac6fbaef4428d712e66483dcb79" + ] +} +</programlisting> + + <para> + The format of the request must include the document ID and one or + more revisions that must be purged. + </para> + + <para> + The response will contain the purge sequence number, and a list of + the document IDs and revisions successfully purged. + </para> + +<programlisting> +{ + "purged" : { + "FishStew" : [ + "17-b3eb5ac6fbaef4428d712e66483dcb79" + ] + }, + "purge_seq" : 11 +} +</programlisting> + + <section id="couchdb-api-db_db-purge_post-indexrebuild"> + + <title>Updating Indexes</title> + + <para> + The number of purges on a database is tracked using a purge + sequence. This is used by the view indexer to optimize the + updating of views that contain the purged documents. + </para> + + <para> + When the indexer identifies that the purge sequence on a + database has changed, it compares the purge sequence of the + database with that stored in the view index. If the difference + between the stored sequence and database is sequence is only 1, + then the indexer uses a cached list of the most recently purged + documents, and then removes these documents from the index + individually. This prevents completely rebuilding the index from + scratch. + </para> + + <para> + If the difference between the stored sequence number and current + database sequence is greater than 1, then the view index is + entirely rebuilt. This is an expensive operation as every + document in the database must be examined. + </para> + + </section> + + </section> + + <section id="couchdb-api-db_db-all-docs_get"> + + <title><literal>GET /db/_all_docs</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-all-docs"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Returns a JSON structure of all of the documents in a given + database. The information is returned as a JSON structure + containing meta information about the return structure, and the + list documents and basic contents, consisting the ID, revision and + key. The key is generated from the document ID. + </para> + + <para role="meta" id="table-couchdb-api-db_db-all-docs"> + <remark role="type" condition="json"/> + + <remark role="src" condition="json"/> + + <remark role="output" condition="itemtable"/> + + <remark role="itemid" condition="all-docs"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + By default the information returned contains only the document ID + and revision. For example, the request: + </para> + +<programlisting role="httprequest"> +GET http://couchdb:5984/recipes/_all_docs +Accept: application/json +</programlisting> + + <para> + Returns the following structure: + </para> + +<programlisting role="httpresponse"> +{ + "total_rows" : 18386, + "rows" : [ + { + "value" : { + "rev" : "1-bc0d5aed1e339b1cc1f29578f3220a45" + }, + "id" : "Aberffrawcake", + "key" : "Aberffrawcake" + }, + { + "value" : { + "rev" : "3-68a20c89a5e70357c20148f8e82ca331" + }, + "id" : "Adukiandorangecasserole-microwave", + "key" : "Adukiandorangecasserole-microwave" + }, + { + "value" : { + "rev" : "3-9b2851ed9b6f655cc4eb087808406c60" + }, + "id" : "Aioli-garlicmayonnaise", + "key" : "Aioli-garlicmayonnaise" + }, + ... + ], + "offset" : 0 +} +</programlisting> + + <para> + The information is returned in the form of a temporary view of all + the database documents, with the returned key consisting of the ID + of the document. The remainder of the interface is therefore + identical to the View query arguments and their behavior. + </para> + +<!-- TODO Add link to view --> + + </section> + + <section id="couchdb-api-db_db-all-docs_post"> + + <title><literal>POST /db/_all_docs</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-all-docs"/> + + <remark role="method" condition="POST"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + The <literal>POST</literal> to <literal>_all_docs</literal> allows + to specify multiple keys to be selected from the database. This + enables you to request multiple documents in a single request, in + place of multiple + <xref + linkend="couchdb-api-dbdoc_db-doc_get"/> requests. + </para> + + <para> + The request body should contain a list of the keys to be returned + as an array to a <literal>keys</literal> object. For example: + </para> + +<programlisting role="httprequest"> +POST http://couchdb:5984/recipes/_all_docs +User-Agent: MyApp/0.1 libwww-perl/5.837 + +{ + "keys" : [ + "Zingylemontart", + "Yogurtraita" + ] +} +</programlisting> + + <para> + The return JSON is the all documents structure, but with only the + selected keys in the output: + </para> + +<programlisting role="httpresponse"> +{ + "total_rows" : 2666, + "rows" : [ + { + "value" : { + "rev" : "1-a3544d296de19e6f5b932ea77d886942" + }, + "id" : "Zingylemontart", + "key" : "Zingylemontart" + }, + { + "value" : { + "rev" : "1-91635098bfe7d40197a1b98d7ee085fc" + }, + "id" : "Yogurtraita", + "key" : "Yogurtraita" + } + ], + "offset" : 0 +} +</programlisting> + +<!-- TODO Add link to view --> + + </section> + + <section id="couchdb-api-db_db-missing-revs_post"> + + <title><literal>POST /db/_missing_revs</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-missing-revs"/> + + <remark role="method" condition="POST"/> + + <remark role="version" condition="inherit"/> + </para> + + </section> + + <section id="couchdb-api-db_db-revs-diff_post"> + + <title><literal>POST /db/_revs_diff</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-revs-diff"/> + + <remark role="method" condition="POST"/> + + <remark role="version" condition="inherit"/> + </para> + + </section> + + <section id="couchdb-api-db_db-security_get"> + + <title><literal>GET /db/_security</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-security"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Gets the current secrity object from the specified database. The + security object consists of two compulsory elements, + <literal>admins</literal> and <literal>readers</literal>, which + are used to specify the list of users and/or roles that have admin + and reader rights to the database respectively. Any additional + fields in the security object are optional. The entire security + object is made available to validation and other internal + functions so that the database can control and limit + functionality. + </para> + + <para> + To get the existing security object you would send the following + request: + </para> + +<programlisting> +{ + "admins" : { + "roles" : [], + "names" : [ + "mc", + "slp" + ] + }, + "readers" : { + "roles" : [], + "names" : [ + "tim", + "brian" + ] + } +} +</programlisting> + + <para role="meta" id="table-couchdb-api-db-json-security"> + <remark role="type" condition="json"/> + + <remark role="src" condition="json"/> + + <remark role="output" condition="itemtable"/> + + <remark role="itemid" condition="security"/> + + <remark role="version" condition="inherit"/> + </para> + + <note> + <para> + If the security object for a database has never beent set, then + the value returned will be empty. + </para> + </note> + + </section> + + <section id="couchdb-api-db_db-security_put"> + + <title><literal>PUT /db/_security</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-security"/> + + <remark role="method" condition="PUT"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Sets the security object for the given database.For example, to + set the security object for the <literal>recipes</literal> + database: + </para> + +<programlisting> +PUT http://couchdb:5984/recipes/_security +Content-Type: application/json + +{ + "admins" : { + "roles" : [], + "names" : [ + "mc", + "slp" + ] + }, + "readers" : { + "roles" : [], + "names" : [ + "tim", + "brian" + ] + } +}</programlisting> + + <para> + If the setting was successful, a JSON status object will be + returned: + </para> + +<programlisting> +{ + "ok" : true +} +</programlisting> + + </section> + + <section id="couchdb-api-db_db-revs-limit_get"> + + <title><literal>GET /db/_revs_limit</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-revs-limit"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Gets the current <literal>revs_limit</literal> (revision limit) + setting. + </para> + + <para> + For example to get the current limit: + </para> + +<programlisting> +GET http://couchdb:5984/recipes/_revs_limit +Content-Type: application/json +</programlisting> + + <para> + The returned information is the current setting as a numerical + scalar: + </para> + +<programlisting> +1000 +</programlisting> + + </section> + + <section id="couchdb-api-db_db-revs-limit_put"> + + <title><literal>PUT /db/_revs_limit</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-revs-limit"/> + + <remark role="method" condition="PUT"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Sets the maximum number of document revisions that will be tracked + by CouchDB, even after compaction has occurred. You can set the + revision limit on a database by using <literal>PUT</literal> with + a scalar integer of the limit that you want to set as the request + body. + </para> + + <para> + For example to set the revs limit to 100 for the + <literal>recipes</literal> database: + </para> + +<programlisting> +PUT http://couchdb:5984/recipes/_revs_limit +Content-Type: application/json + +100 +</programlisting> + + <para> + If the setting was successful, a JSON status object will be + returned: + </para> + +<programlisting> +{ + "ok" : true +} +</programlisting> + + </section> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/couchdb-api-dbdoc-metasrc.xml b/share/docs/couchdb-manual-1.1/couchdb-api-dbdoc-metasrc.xml new file mode 100644 index 000000000..7b680064e --- /dev/null +++ b/share/docs/couchdb-manual-1.1/couchdb-api-dbdoc-metasrc.xml @@ -0,0 +1,1016 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-api-dbdoc"> + + <title>CouchDB API Server Document Methods</title> + + <para> + The CouchDB API Server Document methods detail how to create, read, + update and delete documents within a database. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <para role="meta" id="table-couchdb-api-dbdoc-summary"> + <remark role="title">Document API Calls</remark> + + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="summarytable"/> + + <remark role="filter_class" condition="dbdoc"/> + + <remark role="version" condition="inherit"/> + + <remark role="idprefix" condition="couchdb-api-dbdoc"/> + </para> + + <section id="couchdb-api-dbdoc_db_post"> + + <title><literal>POST /db</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="dbdoc"/> + + <remark role="method" condition="POST"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Create a new document in the specified database, using the + supplied JSON document structure. If the JSON structure includes + the <literal>_id</literal> field, then the document will be + created with the specified document ID. If the + <literal>_id</literal> field is not specified, a new unique ID + will be generated. + </para> + + <para> + For example, you can generate a new document with a generated UUID + using the following request: + </para> + +<programlisting> +POST http://couchdb:5984/recipes/ +Content-Type: application/json + +{ + "servings" : 4, + "subtitle" : "Delicious with fresh bread", + "title" : "Fish Stew" +} +</programlisting> + + <para> + The return JSON will specify the automatically enerated ID and + revision information: + </para> + +<programlisting> +{ + "id" : "64575eef70ab90a2b8d55fc09e00440d", + "ok" : true, + "rev" : "1-9c65296036141e575d32ba9c034dd3ee" +} +</programlisting> + + <section id="couchdb-api-dbdoc_db_post-docid"> + + <title>Specifying the Document ID</title> + + <para> + The document ID can be specified by including the + <literal>_id</literal> field in the JSON of the submitted + record. The following request will create the same document with + the ID <literal>FishStew</literal>: + </para> + +<programlisting> +POST http://couchdb:5984/recipes/ +Content-Type: application/json + +{ + "_id" : "FishStew", + "servings" : 4, + "subtitle" : "Delicious with fresh bread", + "title" : "Fish Stew" +} +</programlisting> + + <para> + The structure of the submitted document is as shown in the table + below: + </para> + + <para role="meta" id="table-couchdb-api-json-document"> + <remark role="type" condition="json"/> + + <remark role="src" condition="json"/> + + <remark role="output" condition="itemtable"/> + + <remark role="itemid" condition="document"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + In either case, the returned JSON will specify the document ID, + revision ID, and status message: + </para> + +<programlisting> +{ + "id" : "FishStew", + "ok" : true, + "rev" : "1-9c65296036141e575d32ba9c034dd3ee" +} + </programlisting> + + </section> + + <section id="couchdb-api-dbdoc_db_batchmode"> + + <title>Batch Mode Writes</title> + + <para> + You can write documents to the database at a higher rate by + using the batch option. This collects document writes together + in memory (on a user-by-user basis) before they are committed to + disk. This increases the risk of the documents not being stored + in the event of a failure, since the documents are not written + to disk immediately. + </para> + + <para> + To use the batched mode, append the <literal>batch=ok</literal> + query argument to the URL of the <literal>PUT</literal> or + <literal>POST</literal> request. The CouchDB server will respond + with a 202 HTTP response code immediately. + </para> + + </section> + + <section id="couchdb-api-dbdoc_db-doc-attachments"> + + <title>Including Attachments</title> + + <para> + You can include one or more attachments with a given document by + incorporating the attachment information within the JSON of the + document. This provides a simpler alternative to loading + documents with attachments than making a separate call (see + <xref + linkend="couchdb-api-dbdoc_db-doc-attachment_put"/>). + </para> + + <para role="meta" id="table-couchdb-api-dbdoc-documentattachments"> + <remark role="type" condition="json"/> + + <remark role="src" condition="json"/> + + <remark role="output" condition="itemtable"/> + + <remark role="itemid" condition="document_with_attachments"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + The <literal>filename</literal> will be the attachment name. For + example, when sending the JSON structure below: + </para> + +<programlisting> +{ + "_id" : "FishStew", + "servings" : 4, + "subtitle" : "Delicious with fresh bread", + "title" : "Fish Stew" + "_attachments" : { + "styling.css" : { + "content-type" : "text/css", + "data" : "cCB7IGZvbnQtc2l6ZTogMTJwdDsgfQo=", + }, + }, +} + </programlisting> + + <para> + The attachment <literal>styling.css</literal> can be accessed + using <literal>/recipes/FishStew/styling.css</literal>. For more + information on attachments, see + <xref + linkend="couchdb-api-dbdoc_db-doc-attachment_get"/>. + </para> + + <para> + The document data embedded in to the structure must be encoded + using base64. + </para> + + </section> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_get"> + + <title><literal>GET /db/doc</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-doc"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Returns the specified <literal>doc</literal> from the specified + <literal>db</literal>. For example, to retrieve the document with + the id <literal>FishStew</literal> you would send the following + request: + </para> + +<programlisting> +GET http://couchdb:5984/recipes/FishStew +Content-Type: application/json +Accept: application/json +</programlisting> + + <para> + The returned JSON is the JSON of the document, including the + document ID and revision number: + </para> + +<programlisting> +{ + "_id" : "FishStew", + "_rev" : "3-a1a9b39ee3cc39181b796a69cb48521c", + "servings" : 4, + "subtitle" : "Delicious with a green salad", + "title" : "Irish Fish Stew" +} + </programlisting> + + <para> + Unless you request a specific revision, the latest revision of the + document will always be returned. + </para> + + <section id="couchdb-api-dbdoc_db-doc_get-attachments"> + + <title>Attachments</title> + + <para> + If the document includes attachments, then the returned + structure will contain a summary of the attachments associatd + with the document, but not the attachment data itself. + </para> + + <para> + The JSON for the returned document will include the + <literal>_attachments</literal> field, with one or more + attachment definitions. For example: + </para> + +<programlisting> +{ + "_id" : "FishStew", + "servings" : 4, + "subtitle" : "Delicious with fresh bread", + "title" : "Fish Stew" + "_attachments" : { + "styling.css" : { + "stub" : true, + "content-type" : "text/css", + "length" : 783426, + }, + }, +} +</programlisting> + + <para> + The format of the returned JSON is shown in the table below: + </para> + + <para role="meta" id="table-couchdb-api-dbdoc-returneddocumentattachments"> + <remark role="type" condition="json"/> + + <remark role="src" condition="json"/> + + <remark role="output" condition="itemtable"/> + + <remark role="itemid" condition="returneddocument_with_attachments"/> + + <remark role="version" condition="inherit"/> + </para> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_get-revs"> + + <title>Getting a List of Revisions</title> + + <para> + You can obtain a list of the revisions for a given document by + adding the <literal>revs=true</literal> parameter to the request + URL. For example: + </para> + +<programlisting> +GET http://couchdb:5984/recipes/FishStew?revs=true +Accept: application/json +</programlisting> + + <para> + The returned JSON structure includes the original document, + including a <literal>_revisions</literal> structure that + includes the revision information: + </para> + +<programlisting> +{ + "servings" : 4, + "subtitle" : "Delicious with a green salad", + "_id" : "FishStew", + "title" : "Irish Fish Stew", + "_revisions" : { + "ids" : [ + "a1a9b39ee3cc39181b796a69cb48521c", + "7c4740b4dcf26683e941d6641c00c39d", + "9c65296036141e575d32ba9c034dd3ee" + ], + "start" : 3 + }, + "_rev" : "3-a1a9b39ee3cc39181b796a69cb48521c" +} +</programlisting> + + <para role="meta" id="table-couchdb-api-dbdoc-document_with_revs"> + <remark role="type" condition="json"/> + + <remark role="src" condition="json"/> + + <remark role="output" condition="itemtable"/> + + <remark role="itemid" condition="document_with_revs"/> + + <remark role="version" condition="inherit"/> + </para> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_get-revsextended"> + + <title>Obtaining an Extended Revision History</title> + + <para> + You can get additional information about the revisions for a + given document by supplying the <literal>revs_info</literal> + argument to the query: + </para> + +<programlisting> +GET http://couchdb:5984/recipes/FishStew?revs_info=true +Accept: application/json +</programlisting> + + <para> + This returns extended revision information, including the + availability and status of each revision: + </para> + +<programlisting> +{ + "servings" : 4, + "subtitle" : "Delicious with a green salad", + "_id" : "FishStew", + "_revs_info" : [ + { + "status" : "available", + "rev" : "3-a1a9b39ee3cc39181b796a69cb48521c" + }, + { + "status" : "available", + "rev" : "2-7c4740b4dcf26683e941d6641c00c39d" + }, + { + "status" : "available", + "rev" : "1-9c65296036141e575d32ba9c034dd3ee" + } + ], + "title" : "Irish Fish Stew", + "_rev" : "3-a1a9b39ee3cc39181b796a69cb48521c" +} +</programlisting> + + <para role="meta" id="table-couchdb-api-dbdoc-document_with_revs_info"> + <remark role="type" condition="json"/> + + <remark role="src" condition="json"/> + + <remark role="output" condition="itemtable"/> + + <remark role="itemid" condition="document_with_revs_info"/> + + <remark role="version" condition="inherit"/> + </para> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_get-specrev"> + + <title>Obtaining a Specific Revision</title> + + <para> + To get a specific revision, use the <literal>rev</literal> + argument to the request, and specify the full revision number: + </para> + +<programlisting> +GET http://couchdb:5984/recipes/FishStew?rev=2-7c4740b4dcf26683e941d6641c00c39d +Accept: application/json +</programlisting> + + <para> + The specified revision of the document will be returned, + including a <literal>_rev</literal> field specifying the + revision that was requested: + </para> + +<programlisting> +{ + "_id" : "FishStew", + "_rev" : "2-7c4740b4dcf26683e941d6641c00c39d", + "servings" : 4, + "subtitle" : "Delicious with a green salad", + "title" : "Fish Stew" +} +</programlisting> + + </section> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_head"> + + <title><literal>HEAD /db/doc</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-doc"/> + + <remark role="method" condition="HEAD"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Returns the HTTP Headers containing a minimal amount of + information about the specified document. The method supports the + same query arguments as the <literal>GET</literal> method, but + only the header information (including document size, and the + revision as an ETag), is returned. For example, a simple + <literal>HEAD</literal> request: + </para> + +<programlisting> +HEAD http://couchdb:5984/recipes/FishStew +Content-Type: application/json + </programlisting> + + <para> + Returns the following HTTP Headers: + </para> + +<programlisting> +HTTP/1.1 200 OK +Server: CouchDB/1.0.1 (Erlang OTP/R13B) +Etag: "7-a19a1a5ecd946dad70e85233ba039ab2" +Date: Fri, 05 Nov 2010 14:54:43 GMT +Content-Type: text/plain;charset=utf-8 +Content-Length: 136 +Cache-Control: must-revalidate +</programlisting> + + <para> + The <literal>Etag</literal> header shows the current revision for + the requested document, and the <literal>Content-Length</literal> + specifies the length of the data, if the document were requested + in full. + </para> + + <para> + Adding any of the query arguments (as supported by + <link linkend="couchdb-api-dbdoc_db-doc_get"><literal>GET</literal></link> + method), then the resulting HTTP Headers will correspond to what + would be returned. Note that the current revision is not returned + when the <literal>refs_info</literal> argument is used. For + example: + </para> + +<programlisting> +HTTP/1.1 200 OK +Server: CouchDB/1.0.1 (Erlang OTP/R13B) +Date: Fri, 05 Nov 2010 14:57:16 GMT +Content-Type: text/plain;charset=utf-8 +Content-Length: 609 +Cache-Control: must-revalidate +</programlisting> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_put"> + + <title><literal>PUT /db/doc</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-doc"/> + + <remark role="method" condition="PUT"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + The <literal>PUT</literal> method creates a new named document, or + creates a new revision of the existing document. Unlike the + <link linkend="couchdb-api-dbdoc_db_post"><literal>POST</literal></link> + method, you must specify the document ID in the request URL. + </para> + + <para> + For example, to create the docment <literal>FishStew</literal>, + you would send the following request: + </para> + +<programlisting>PUT http://couchdb:5984/recipes/FishStew +Content-Type: application/json + +{ + "servings" : 4, + "subtitle" : "Delicious with fresh bread", + "title" : "Fish Stew" +} +</programlisting> + + <para> + The return type is JSON of the status, document ID,and revision + number: + </para> + +<programlisting> +{ + "id" : "FishStew", + "ok" : true, + "rev" : "1-9c65296036141e575d32ba9c034dd3ee" +} +</programlisting> + + <section id="couchdb-api-dbdoc_db-doc_put-update"> + + <title>Updating an Existing Document</title> + + <para> + To update an existing document you must specify the current + revision number within the <literal>_rev</literal> parameter. + For example: + </para> + +<programlisting> +PUT http://couchdb:5984/recipes/FishStew +Content-Type: application/json + +{ + "_rev" : "1-9c65296036141e575d32ba9c034dd3ee", + "servings" : 4, + "subtitle" : "Delicious with fresh salad", + "title" : "Fish Stew" +} +</programlisting> + + <para> + Alternatively, you can supply the current revision number in the + <literal>If-Match</literal> HTTP header of the request. For + example: + </para> + +<programlisting> +PUT http://couchdb:5984/recipes/FishStew +If-Match: 2-d953b18035b76f2a5b1d1d93f25d3aea +Content-Type: application/json + +{ + "servings" : 4, + "subtitle" : "Delicious with fresh salad", + "title" : "Fish Stew" +} +</programlisting> + + <para> + The JSON returned will include the updated revision number: + </para> + +<programlisting> +{ + "id" : "FishStew99", + "ok" : true, + "rev" : "2-d953b18035b76f2a5b1d1d93f25d3aea" +} +</programlisting> + + <para> + For information on batched writes, which can provide improved + performance, see + <xref linkend="couchdb-api-dbdoc_db_batchmode"/>. + </para> + + </section> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_delete"> + + <title><literal>DELETE /db/doc</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-doc"/> + + <remark role="method" condition="DELETE"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Deletes the specified document from the database. You must supply + the current (latest) revision, either by using the + <literal>rev</literal> parameter to specify the revision: + </para> + +<programlisting> +DELETE http://couchdb:5984/recipes/FishStew?rev=3-a1a9b39ee3cc39181b796a69cb48521c +Content-Type: application/json +</programlisting> + + <para> + Alternatively, you can use ETags with the + <literal>If-Match</literal> field: + </para> + +<programlisting> +DELETE http://couchdb:5984/recipes/FishStew +If-Match: 3-a1a9b39ee3cc39181b796a69cb48521c +Content-Type: application/json + </programlisting> + + <para> + The returned JSON contains the document ID, revision and status: + </para> + +<programlisting> +{ + "id" : "FishStew", + "ok" : true, + "rev" : "4-2719fd41187c60762ff584761b714cfb" +} +</programlisting> + + <note> + <para> + Note that deletion of a record increments the revision number. + The use of a revision for deletion of the record allows + replication of the database to correctly track the deletion in + synchronized copies. + </para> + </note> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_copy"> + + <title><literal>COPY /db/doc</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-doc"/> + + <remark role="method" condition="COPY"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + The <literal>COPY</literal> command (which is non-standard HTTP) + copies an existing document to a new or existing document. + </para> + + <para> + The source document is specified on the request line, with the + <literal>Destination</literal> HTTP Header of the request + specifying the target document. + </para> + + <section id="couchdb-api-dbdoc_db-doc_copy-simple"> + + <title>Copying a Document</title> + + <para> + You can copy the latest version of a document to a new document + by specifying the current document and target document: + </para> + +<programlisting> +COPY http://couchdb:5984/recipes/FishStew +Content-Type: application/json +Destination: IrishFishStew +</programlisting> + + <para> + The above request copies the document + <literal>FishStew</literal> to the new document + <literal>IrishFishStew</literal>. The response is the ID and + revision of the new document. + </para> + +<programlisting> +{ + "id" : "IrishFishStew", + "rev" : "1-9c65296036141e575d32ba9c034dd3ee" +} +</programlisting> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_copy-specrev"> + + <title>Copying from a Specific Revision</title> + + <para> + To copy <emphasis>from</emphasis> a specific version, use the + <literal>rev</literal> argument to the query string: + </para> + +<programlisting> +COPY http://couchdb:5984/recipes/FishStew?rev=5-acfd32d233f07cea4b4f37daaacc0082 +Content-Type: application/json +Destination: IrishFishStew +</programlisting> + + <para> + The new document will be created using the information in the + specified revision of the source document. + </para> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_copy-existing"> + + <title>Copying to an Existing Document</title> + + <para> + To copy to an existing document, you must specify the current + revision string for the target document, using the + <literal>rev</literal> parameter to the + <literal>Destination</literal> HTTP Header string. For example: + </para> + +<programlisting> +COPY http://couchdb:5984/recipes/FishStew +Content-Type: application/json +Destination: IrishFishStew?rev=1-9c65296036141e575d32ba9c034dd3ee +</programlisting> + + <para> + The return value will be the new revision of the copied + document: + </para> + +<programlisting> +{ + "id" : "IrishFishStew", + "rev" : "2-55b6a1b251902a2c249b667dab1c6692" +} +</programlisting> + + </section> + + </section> + + <section id="couchdb-api-dbdoc_db-doc-attachment_get"> + + <title><literal>GET /db/doc/attachment</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-doc-attachment"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Returns the file attachment <literal>attachment</literal> + associated with the document <literal>doc</literal>. The raw data + of the associated attachment is returned (just as if you were + accessing a static file. The returned HTTP + <literal>Content-type</literal> will be the same as the content + type set when the document attachment was submitted into the + database. + </para> + + </section> + + <section id="couchdb-api-dbdoc_db-doc-attachment_put"> + + <title><literal>PUT /db/doc/attachment</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-doc-attachment"/> + + <remark role="method" condition="PUT"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Upload the supplied content as an attachment to the specified + document (<literal>doc</literal>). The + <literal>attachment</literal> name provided must be a URL encoded + string. You must also supply either the <literal>rev</literal> + query argument or the <literal>If-Match</literal> HTTP header for + validation, and the HTTP headers (to set the attacment content + type). The content type is used when the attachment is requested + as the corresponding content-type in the returned document header. + </para> + + <para> + For example, you could upload a simple text document using the + following request: + </para> + +<programlisting> +PUT http://couchdb:5984/recipes/FishStew/basic?rev=8-a94cb7e50ded1e06f943be5bfbddf8ca +Content-Length: 10 +Content-Type: text/plain + +Roast it + +</programlisting> + + <para> + Or by using the <literal>If-Match</literal> HTTP header: + </para> + +<programlisting> +PUT http://couchdb:5984/recipes/FishStew/basic +If-Match: 8-a94cb7e50ded1e06f943be5bfbddf8ca +Content-Length: 10 +Content-Type: text/plain + +Roast it + +</programlisting> + + <para> + The returned JSON contains the new document information: + </para> + +<programlisting> +{ + "id" : "FishStew", + "ok" : true, + "rev" : "9-247bb19a41bfd9bfdaf5ee6e2e05be74" +} +</programlisting> + + <note> + <para> + Uploading an attachment updates the corresponding document + revision. Revisions are tracked for the parent document, not + individual attachments. + </para> + </note> + + <section id="couchdb-api-dbdoc_db-doc-attachment_put-existing"> + + <title>Updating an Existing Attachment</title> + + <para> + Uploading an attachment using an existing attachment name will + update the corresponding stored content of the database. Since + you must supply the revision information to add an attachment to + a document, this serves as validation to update the existing + attachment. + </para> + + </section> + + </section> + + <section id="couchdb-api-dbdoc_db-doc-attachment_delete"> + + <title><literal>DELETE /db/doc/attachment</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-doc-attachment"/> + + <remark role="method" condition="DELETE"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Deletes the attachment <literal>attachment</literal> to the + specified <literal>doc</literal>. You must supply the + <literal>rev</literal> argument with the current revision to + delete the attachment. + </para> + + <para> + For example to delete the attachment <literal>basic</literal> from + the recipe <literal>FishStew</literal>: + </para> + +<programlisting> +DELETE http://couchdb:5984/recipes/FishStew/basic?rev=9-247bb19a41bfd9bfdaf5ee6e2e05be74 +Content-Type: application/json + + </programlisting> + + <para> + The returned JSON contains the updated revision information: + </para> + +<programlisting> +{ + "id" : "FishStew", + "ok" : true, + "rev" : "10-561bf6b1e27615cee83d1f48fa65dd3e" +} +</programlisting> + + </section> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/couchdb-api-design-metasrc.xml b/share/docs/couchdb-manual-1.1/couchdb-api-design-metasrc.xml new file mode 100644 index 000000000..f4edf75a3 --- /dev/null +++ b/share/docs/couchdb-manual-1.1/couchdb-api-design-metasrc.xml @@ -0,0 +1,1462 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-api-design"> + + <title>CouchDB API Server Design Document Methods</title> + + <para> + In CouchDB, design documents provide the main interface for building + a CouchDB application. The design document defines the views used to + extract information from CouchDB through one or more views. Design + documents are created within your CouchDB instance in the same way + as you create database documents, but the content and definition of + the documents is different. Design Documents are named using an ID + defined with the design document URL path, and this URL can then be + used to access the database contents. + </para> + + <para> + Views and lists operate together to provide automated (and + formatted) output from your database. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <para role="meta" id="table-couchdb-api-design-summary"> + <remark role="title">Design Document API Calls</remark> + + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="summarytable"/> + + <remark role="filter_class" condition="design"/> + + <remark role="version" condition="inherit"/> + + <remark role="idprefix" condition="couchdb-api-design"/> + </para> + + <section id="couchdb-api-design_db-design-designdoc_get"> + + <title><literal>GET /db/_design/design-doc</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-design-designdoc"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Returns the specified design document, + <literal>design-doc</literal> from the specified + <literal>db</literal>. For example, to retrieve the design + document <literal>recipes</literal> you would send the following + request: + </para> + +<programlisting> +GET http://couchdb:5984/recipes/_design/recipes +Content-Type: application/json +</programlisting> + + <para> + The returned string will be the JSON of the design document: + </para> + +<programlisting> +{ + "_id" : "_design/recipes", + "_rev" : "5-39f56a392b86bbee57e2138921346406" + "language" : "javascript", + "views" : { + "by_recipe" : { + "map" : "function(doc) { if (doc.title != null) emit(doc.title, doc) }" + }, + }, +} +</programlisting> + + <para> + A list of the revisions can be obtained by using the + <literal>revs</literal> query argument, or an extended list of + revisions using the <literal>revs_info</literal> query argument. + This operates in the same way as for other documents. Fur further + examples, see + <xref + linkend="couchdb-api-dbdoc_db-doc_get"/>. + </para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc_put"> + + <title><literal>PUT /db/_design/design-doc</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-design-designdoc"/> + + <remark role="method" condition="PUT"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Upload the specified design document, + <literal>design-doc</literal>, to the specified database. The + design document should follow the definition of a design document, + as summarised in the following table. + </para> + + <para role="meta" id="table-couchdb-api-json-designdoc"> + <remark role="type" condition="json"/> + + <remark role="src" condition="json"/> + + <remark role="output" condition="itemtable"/> + + <remark role="itemid" condition="design-doc"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + For more information on writing views, see + <xref + linkend="couchdb-api-functional-views"/>. + </para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc_delete"> + + <title><literal>DELETE /db/_design/design-doc</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-design-designdoc"/> + + <remark role="method" condition="DELETE"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Delete an existing design document. Deleting a design document + also deletes all of the associated view indexes, and recovers the + corresponding space on disk for the indexes in question. + </para> + + <para> + To delete, you must specify the current revision of the design + document using the <literal>rev</literal> query argument. + </para> + + <para> + For example: + </para> + +<programlisting> +DELETE http://couchdb:5984/recipes/_design/recipes?rev=2-ac58d589b37d01c00f45a4418c5a15a8 +Content-Type: application/json +</programlisting> + + <para> + The response contains the delete document ID and revision: + </para> + +<programlisting> +{ + "id" : "recipe/_design/recipes" + "ok" : true, + "rev" : "3-7a05370bff53186cb5d403f861aca154", +} +</programlisting> + + </section> + + <section id="couchdb-api-design_db-design-designdoc_copy"> + + <title><literal>COPY /db/_design/design-doc</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-design-designdoc"/> + + <remark role="method" condition="COPY"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + The <literal>COPY</literal> command (non-standard HTTP) copies an + existing design document to a new or existing document. + </para> + + <para> + The source design document is specified on the request line, with + the <literal>Destination</literal> HTTP Header of the request + specifying the target document. + </para> + + <section id="couchdb-api-design_db-design-designdoc_copy-simple"> + + <title>Copying a Design Document</title> + + <para> + To copy the latest version of a design document to a new + document you specify the base document and target document: + </para> + +<programlisting> +COPY http://couchdb:5984/recipes/_design/recipes +Content-Type: application/json +Destination: /recipes/_design/recipelist +</programlisting> + + <para> + The above request copies the design document + <literal>recipes</literal> to the new design document + <literal>recipelist</literal>. The response is the ID and + revision of the new document. + </para> + +<programlisting> +{ + "id" : "recipes/_design/recipelist" + "rev" : "1-9c65296036141e575d32ba9c034dd3ee", +} +</programlisting> + + <note> + <para> + Copying a design document does automatically reconstruct the + view indexes. These will be recreated, as with other views, + the first time the new view is accessed. + </para> + </note> + + </section> + + <section id="couchdb-api-design_db-design-designdoc_copy-specrev"> + + <title>Copying from a Specific Revision</title> + + <para> + To copy <emphasis>from</emphasis> a specific version, use the + <literal>rev</literal> argument to the query string: + </para> + +<programlisting> +COPY http://couchdb:5984/recipes/_design/recipes?rev=1-e23b9e942c19e9fb10ff1fde2e50e0f5 +Content-Type: application/json +Destination: recipes/_design/recipelist +</programlisting> + + <para> + The new design document will be created using the specified + revision of the source document. + </para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc_copy-existing"> + + <title>Copying to an Existing Design Document</title> + + <para> + To copy to an existing document, you must specify the current + revision string for the target document, using the + <literal>rev</literal> parameter to the + <literal>Destination</literal> HTTP Header string. For example: + </para> + +<programlisting> +COPY http://couchdb:5984/recipes/_design/recipes +Content-Type: application/json +Destination: recipes/_design/recipelist?rev=1-9c65296036141e575d32ba9c034dd3ee +</programlisting> + + <para> + The return value will be the new revision of the copied + document: + </para> + +<programlisting> +{ + "id" : "recipes/_design/recipes" + "rev" : "2-55b6a1b251902a2c249b667dab1c6692", +} +</programlisting> + + </section> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-attachment_get"> + + <title><literal>GET /db/_design/design-doc/attachment</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-design-designdoc-attachment"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Returns the file attachment <literal>attachment</literal> + associated with the design document + <literal>/_design_/design-doc</literal>. The raw data of the + associated attachment is returned (just as if you were accessing a + static file. The returned HTTP <literal>Content-type</literal> + will be the same as the content type set when the document + attachment was submitted into the database. + </para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-attachment_put"> + + <title><literal>PUT /db/_design/design-doc/attachment</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-design-designdoc-attachment"/> + + <remark role="method" condition="PUT"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Upload the supplied content as an attachment to the specified + design document (<literal>/_design/design-doc</literal>). The + <literal>attachment</literal> name provided must be a URL encoded + string. You must also supply either the <literal>rev</literal> + query argument or the <literal>If-Match</literal> HTTP header for + validation, and the HTTP headers (to set the attacment content + type). The content type is used when the attachment is requested + as the corresponding content-type in the returned document header. + </para> + + <para> + For example, you could upload a simple text document using the + following request: + </para> + +<programlisting> +PUT http://couchdb:5984/recipes/_design/recipes/view.css?rev=7-f7114d4d81124b223283f3e89eee043e +Content-Length: 39 +Content-Type: text/plain + +div.recipetitle { +font-weight: bold; +} + +</programlisting> + + <para> + Or by using the <literal>If-Match</literal> HTTP header: + </para> + +<programlisting> +PUT http://couchdb:5984/recipes/FishStew/basic +If-Match: 7-f7114d4d81124b223283f3e89eee043e +Content-Length: 39 +Content-Type: text/plain + +div.recipetitle { +font-weight: bold; +} + +</programlisting> + + <para> + The returned JSON contains the new document information: + </para> + +<programlisting> +{ + "id" : "_design/recipes" + "ok" : true, + "rev" : "8-cb2b7d94eeac76782a02396ba70dfbf5", +} +</programlisting> + + <note> + <para> + Uploading an attachment updates the corresponding document + revision. Revisions are tracked for the parent document, not + individual attachments. + </para> + </note> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-attachment_delete"> + + <title><literal>DELETE /db/_design/design-doc/attachment</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-design-designdoc-attachment"/> + + <remark role="method" condition="DELETE"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Deletes the attachment <literal>attachment</literal> to the + specified <literal>_design/design-doc</literal>. You must supply + the <literal>rev</literal> argument with the current revision to + delete the attachment. + </para> + + <para> + For example to delete the attachment <literal>view.css</literal> + from the design document <literal>recipes</literal>: + </para> + +<programlisting> +DELETE http://couchdb:5984/recipes/_design/recipes/view.css?rev=9-3db559f13a845c7751d407404cdeaa4a + </programlisting> + + <para> + The returned JSON contains the updated revision information for + the parent document: + </para> + +<programlisting> +{ + "id" : "_design/recipes" + "ok" : true, + "rev" : "10-f3b15bb408961f8dcc3d86c7d3b54c4c", +} +</programlisting> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-info_get"> + + <title><literal>GET /db/_design/design-doc/_info</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-design-designdoc-info"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Obtains information about a given design document, including the + index, index size and current status of the design document and + associated index information. + </para> + + <para> + For example, to get the information for the + <literal>recipes</literal> design document: + </para> + +<programlisting> +GET http://couchdb:5984/recipes/_design/recipes/_info +Content-Type: application/json +</programlisting> + + <para> + This returns the following JSON structure: + </para> + +<programlisting> +{ + "name" : "recipes" + "view_index" : { + "compact_running" : false, + "updater_running" : false, + "language" : "javascript", + "purge_seq" : 10, + "waiting_commit" : false, + "waiting_clients" : 0, + "signature" : "fc65594ee76087a3b8c726caf5b40687", + "update_seq" : 375031, + "disk_size" : 16491 + }, +} +</programlisting> + + <para> + The individual fields in the returned JSON structure are detailed + in + <xref linkend="table-couchdb-api-design_db-designdoc-info-json"/>. + </para> + + <para role="meta" id="table-couchdb-api-design_db-designdoc-info-json"> + <remark role="title">Design Document Info JSON Contents</remark> + + <remark role="type" condition="json"/> + + <remark role="src" condition="json"/> + + <remark role="output" condition="itemtable"/> + + <remark role="itemid" condition="design-doc_info"/> + + <remark role="version" condition="inherit"/> + </para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-view-viewname_get"> + + <title><literal>GET /db/_design/design-doc/_view/view-name</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-design-designdoc-view-viewname"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Executes the specified <literal>view-name</literal> from the + specified <literal>design-doc</literal> design document. + </para> + + <section + id="couchdb-api-design_db-design-designdoc-view-viewname_get-indexes"> + + <title>Querying Views and Indexes</title> + + <para> + The definition of a view within a design document also creates + an index based on the key information defined within each view. + The production and use of the index significantly increases the + speed of access and searching or selecting documents from the + view. + </para> + + <para> + However, the index is not updated when new documents are added + or modified in the database. Instead, the index is generated or + updated, either when the view is first accessed, or when the + view is accessed after a document has been updated. In each + case, the index is updated before the view query is executed + against the database. + </para> + + <para> + View indexes are updated incrementally in the following + situations: + </para> + + <itemizedlist> + + <listitem> + <para> + A new document has been added to the database. + </para> + </listitem> + + <listitem> + <para> + A document has been deleted from the database. + </para> + </listitem> + + <listitem> + <para> + A document in the database has been updated. + </para> + </listitem> + + </itemizedlist> + + <para> + View indexes are rebuilt entirely when the view definition + changes. To achieve this, a 'fingerprint' of the view definition + is created when the design document is updated. If the + fingerprint changes, then the view indexes are entirely rebuilt. + This ensures that changes to the view definitions are reflected + in the view indexes. + </para> + + <note> + <para> + View index rebuilds occur when one view from the same the view + group (i.e. all the views defined within a single a design + document) has been determined as needing a rebuild. For + example, if if you have a design document with different + views, and you update the database, all three view indexes + within the design document will be updated. + </para> + </note> + + <para> + Because the view is updated when it has been queried, it can + result in a delay in returned information when the view is + accessed, especially if there are a large number of documents in + the database and the view index does not exist. There are a + number of ways to mitigate, but not completely eliminate, these + issues. These include: + </para> + + <itemizedlist> + + <listitem> + <para> + Create the view definition (and associated design documents) + on your database before allowing insertion or updates to the + documents. If this is allowed while the view is being + accessed, the index can be updated incrementally. + </para> + </listitem> + + <listitem> + <para> + Manually force a view request from the database. You can do + this either before users are allowed to use the view, or you + can access the view manually after documents are added or + updated. + </para> + </listitem> + + <listitem> + <para> + Use the <literal>/db/_changes</literal> method to monitor + for changes to the database and then access the view to + force the corresponding view index to be updated. See + <xref + linkend="couchdb-api-db_db-changes_get"/> + for more information. + </para> + </listitem> + + <listitem> + <para> + Use a monitor with the + <literal>update_notification</literal> section of the + CouchDB configuration file to monitor for changes to your + database, and trigger a view query to force the view to be + updated. For more information, see + <xref + linkend="couchdb-single-configuration-update_notification"/>. + </para> + </listitem> + + </itemizedlist> + + <para> + None of these can completely eliminate the need for the indexes + to be rebuilt or updated when the view is accessed, but they may + lessen the effects on end-users of the index update affecting + the user experience. + </para> + + <para> + Another alternative is to allow users to access a 'stale' + version of the view index, rather than forcing the index to be + updated and displaying the updated results. Using a stale view + may not return the latest information, but will return the + results of the view query using an existing version of the + index. + </para> + + <para> + For example, to access the existing stale view + <literal>by_recipe</literal> in the <literal>recipes</literal> + design document: + </para> + +<programlisting>http://couchdb:5984/recipes/_design/recipes/_view/by_recipe?stale=ok</programlisting> + + <para> + Accessing a stale view: + </para> + + <itemizedlist> + + <listitem> + <para> + Does not trigger a rebuild of the view indexes, even if + there have been changes since the last access. + </para> + </listitem> + + <listitem> + <para> + Returns the current version of the view index, if a current + version exists. + </para> + </listitem> + + <listitem> + <para> + Returns an empty result set if the given view index does + exist. + </para> + </listitem> + + </itemizedlist> + + <para> + As an alternative, you use the <literal>update_after</literal> + value to the <option>stale</option> paramater. This causes the + view to be returned as a stale view, but for the update process + to be triggered after the view information has been returned to + the client. + </para> + + <para> + In addition to using stale views, you can also make use of the + <literal>update_seq</literal> query argument. Using this query + argument generates the view information including the update + sequence of the database from which the view was generated. The + returned value can be compared this to the current update + sequence exposed in the database information (returned by + <xref linkend="couchdb-api-db_db_get"/>). + </para> + + </section> + + <section + id="couchdb-api-design_db-design-designdoc-view-viewname_get-sorting"> + + <title>Sorting Returned Rows</title> + + <para> + Each element within the returned array is sorted using native + UTF-8 sorting according to the contents of the key portion of + the emitted content. The basic order of output is as follows: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal>null</literal> + </para> + </listitem> + + <listitem> + <para> + <literal>false</literal> + </para> + </listitem> + + <listitem> + <para> + <literal>true</literal> + </para> + </listitem> + + <listitem> + <para> + Numbers + </para> + </listitem> + + <listitem> + <para> + Text (case sensitive, lowercase first) + </para> + </listitem> + + <listitem> + <para> + Arrays (according to the values of each element, in order) + </para> + </listitem> + + <listitem> + <para> + Objects (according to the values of keys, in key order) + </para> + </listitem> + + </itemizedlist> + +<!-- TODO: Point to the view definition docs for information on the collation + specification --> + + <para> + You can reverse the order of the returned view information by + using the <literal>descending</literal> query value set to true. + For example, Retrieving the list of recipes using the + <literal>by_title</literal> (limited to 5 records) view: + </para> + +<programlisting> +{ + "offset" : 0, + "rows" : [ + { + "id" : "3-tiersalmonspinachandavocadoterrine", + "key" : "3-tier salmon, spinach and avocado terrine", + "value" : [ + null, + "3-tier salmon, spinach and avocado terrine" + ] + }, + { + "id" : "Aberffrawcake", + "key" : "Aberffraw cake", + "value" : [ + null, + "Aberffraw cake" + ] + }, + { + "id" : "Adukiandorangecasserole-microwave", + "key" : "Aduki and orange casserole - microwave", + "value" : [ + null, + "Aduki and orange casserole - microwave" + ] + }, + { + "id" : "Aioli-garlicmayonnaise", + "key" : "Aioli - garlic mayonnaise", + "value" : [ + null, + "Aioli - garlic mayonnaise" + ] + }, + { + "id" : "Alabamapeanutchicken", + "key" : "Alabama peanut chicken", + "value" : [ + null, + "Alabama peanut chicken" + ] + } + ], + "total_rows" : 2667 +} +</programlisting> + + <para> + Requesting the same in descending order will reverse the entire + view content. For example the request + </para> + +<programlisting> +GET http://couchdb:5984/recipes/_design/recipes/_view/by_title?limit=5&descending=true +Accept: application/json +Content-Type: application/json</programlisting> + + <para> + Returns the last 5 records from the view: + </para> + +<programlisting> +{ + "offset" : 0, + "rows" : [ + { + "id" : "Zucchiniinagrodolcesweet-sourcourgettes", + "key" : "Zucchini in agrodolce (sweet-sour courgettes)", + "value" : [ + null, + "Zucchini in agrodolce (sweet-sour courgettes)" + ] + }, + { + "id" : "Zingylemontart", + "key" : "Zingy lemon tart", + "value" : [ + null, + "Zingy lemon tart" + ] + }, + { + "id" : "Zestyseafoodavocado", + "key" : "Zesty seafood avocado", + "value" : [ + null, + "Zesty seafood avocado" + ] + }, + { + "id" : "Zabaglione", + "key" : "Zabaglione", + "value" : [ + null, + "Zabaglione" + ] + }, + { + "id" : "Yogurtraita", + "key" : "Yogurt raita", + "value" : [ + null, + "Yogurt raita" + ] + } + ], + "total_rows" : 2667 +} +</programlisting> + + <para> + The sorting direction is applied before the filtering applied + using the <literal>startkey</literal> and + <literal>endkey</literal> query arguments. For example the + following query: + </para> + +<programlisting> +GET http://couchdb:5984/recipes/_design/recipes/_view/by_ingredient?startkey=%22carrots%22&endkey=%22egg%22 +Accept: application/json +Content-Type: application/json +</programlisting> + + <para> + Will operate correctly when listing all the matching entries + between <quote>carrots</quote> and <literal>egg</literal>. If + the order of output is reversed with the + <literal>descending</literal> query argument, the view request + will return no entries: + </para> + +<programlisting> +GET http://couchdb:5984/recipes/_design/recipes/_view/by_ingredient?descending=true&startkey=%22carrots%22&endkey=%22egg%22 +Accept: application/json +Content-Type: application/json +</programlisting> + + <para> + The returned result is empty: + </para> + +<programlisting> +{ + "total_rows" : 26453, + "rows" : [], + "offset" : 21882 +} +</programlisting> + + <para> + The results will be empty because the entries in the view are + reversed before the key filter is applied, and therefore the + <literal>endkey</literal> of <quote>egg</quote> will be seen + before the <literal>startkey</literal> of + <quote>carrots</quote>, resulting in an empty list. + </para> + + <para> + Instead, you should reverse the values supplied to the + <literal>startkey</literal> and <literal>endkey</literal> + parameters to match the descending sorting applied to the keys. + Changing the previous example to: + </para> + +<programlisting> +GET http://couchdb:5984/recipes/_design/recipes/_view/by_ingredient?descending=true&startkey=%22egg%22&endkey=%22carrots%22 +Accept: application/json +Content-Type: application/json +</programlisting> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-view-viewname_get-ranges"> + + <title>Specifying Start and End Values</title> + + <para> + The <literal>startkey</literal> and <literal>endkey</literal> + query arguments can be used to specify the range of values to be + displayed when querying the view. + </para> + + <note> + <para> + The values + </para> + </note> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-view-viewname_get-limit"> + + <title>Using Limits and Skipping Rows</title> + + <para> + TBC + </para> + + </section> + + <section + id="couchdb-api-design_db-design-designdoc-view-viewname_get-reduction"> + + <title>View Reduction and Grouping</title> + + <para> + TBC + </para> + + </section> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-view-viewname_post"> + + <title><literal>POST /db/_design/design-doc/_view/view-name</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-design-designdoc-view-viewname"/> + + <remark role="method" condition="POST"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Executes the specified <literal>view-name</literal> from the + specified <literal>design-doc</literal> design document. Unlike + the <literal>GET</literal> method for accessing views, the + <literal>POST</literal> method supports the specification of + explicit keys to be retrieved from the view results. The remainder + of the <literal>POST</literal> view functionality is identical to + the + <xref + linkend="couchdb-api-design_db-design-designdoc-view-viewname_get"/> + fun + </para> + + <para> + For example, the request below will return all the recipes where + the key for the view matches either <quote>claret</quote> or + <quote>clear apple cider</quote> : + </para> + +<programlisting> +POST http://couchdb:5984/recipes/_design/recipes/_view/by_ingredient +Content-Type: application/json + +{ + "keys" : [ + "claret", + "clear apple juice" + ] +} + </programlisting> + + <para> + The returned view data contains the standard view information, but + only where the keys match. + </para> + +<programlisting> +{ + "total_rows" : 26484, + "rows" : [ + { + "value" : [ + "Scotch collops" + ], + "id" : "Scotchcollops", + "key" : "claret" + }, + { + "value" : [ + "Stand pie" + ], + "id" : "Standpie", + "key" : "clear apple juice" + } + ], + "offset" : 6324 +} +</programlisting> + + <section + id="couchdb-api-design_db-design-designdoc-view-viewname_post-multidoc"> + + <title>Multi-document Fetching</title> + + <para> + By combining the <literal>POST</literal> method to a given view + with the <literal>include_docs=true</literal> query argument you + can obtain multiple documents from a database. The result is + more efficient than using multiple + <xref + linkend="couchdb-api-dbdoc_db-doc_get"/> + requests. + </para> + + <para> + For example, sending the following request for ingredients + matching <quote>claret</quote> and <quote>clear apple + juice</quote>: + </para> + +<programlisting> +POST http://couchdb:5984/recipes/_design/recipes/_view/by_ingredient?include_docs=true +Content-Type: application/json + +{ + "keys" : [ + "claret", + "clear apple juice" + ] +} +</programlisting> + + <para> + Returns the full document for each recipe: + </para> + +<programlisting> +{ + "offset" : 6324, + "rows" : [ + { + "doc" : { + "_id" : "Scotchcollops", + "_rev" : "1-bcbdf724f8544c89697a1cbc4b9f0178", + "cooktime" : "8", + "ingredients" : [ + { + "ingredient" : "onion", + "ingredtext" : "onion, peeled and chopped", + "meastext" : "1" + }, + ... + ], + "keywords" : [ + "cook method.hob, oven, grill@hob", + "diet@wheat-free", + "diet@peanut-free", + "special collections@classic recipe", + "cuisine@british traditional", + "diet@corn-free", + "diet@citrus-free", + "special collections@very easy", + "diet@shellfish-free", + "main ingredient@meat", + "occasion@christmas", + "meal type@main", + "diet@egg-free", + "diet@gluten-free" + ], + "preptime" : "10", + "servings" : "4", + "subtitle" : "This recipe comes from an old recipe book of 1683 called 'The Gentlewoman's Kitchen'. This is an excellent way of making a rich and full-flavoured meat dish in a very short time.", + "title" : "Scotch collops", + "totaltime" : "18" + }, + "id" : "Scotchcollops", + "key" : "claret", + "value" : [ + "Scotch collops" + ] + }, + { + "doc" : { + "_id" : "Standpie", + "_rev" : "1-bff6edf3ca2474a243023f2dad432a5a", + "cooktime" : "92", + "ingredients" : [ +... ], + "keywords" : [ + "diet@dairy-free", + "diet@peanut-free", + "special collections@classic recipe", + "cuisine@british traditional", + "diet@corn-free", + "diet@citrus-free", + "occasion@buffet party", + "diet@shellfish-free", + "occasion@picnic", + "special collections@lunchbox", + "main ingredient@meat", + "convenience@serve with salad for complete meal", + "meal type@main", + "cook method.hob, oven, grill@hob / oven", + "diet@cow dairy-free" + ], + "preptime" : "30", + "servings" : "6", + "subtitle" : "Serve this pie with pickled vegetables and potato salad.", + "title" : "Stand pie", + "totaltime" : "437" + }, + "id" : "Standpie", + "key" : "clear apple juice", + "value" : [ + "Stand pie" + ] + } + ], + "total_rows" : 26484 +} +</programlisting> + + </section> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-show-showname_get"> + + <title><literal>POST /db/_design/design-doc/_show/show-name</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-design-designdoc-show-showname"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para></para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-show-showname-doc_get"> + + <title><literal>POST /db/_design/design-doc/_show/show-name/doc</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-design-designdoc-show-showname-doc"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para></para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-list-listname-otherdesigndoc-viewname_get"> + + <title><literal>GET + /db/_design/design-doc/_list/list-name/other-design-doc/view-name</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-design-designdoc-list-listname-otherdesigndoc-viewname"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-list-listname-otherdesigndoc-viewname_post"> + + <title><literal>POST + /db/_design/design-doc/_list/list-name/other-design-doc/view-name</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-design-designdoc-list-listname-otherdesigndoc-viewname"/> + + <remark role="method" condition="POST"/> + + <remark role="version" condition="inherit"/> + </para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-list-listname-viewname_get"> + + <title><literal>GET /db/_design/design-doc/_list/list-name/view-name</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-design-designdoc-list-listname-viewname"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-list-listname-viewname_post"> + + <title><literal>POST /db/_design/design-doc/_list/list-name/view-name</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-design-designdoc-list-listname-viewname"/> + + <remark role="method" condition="POST"/> + + <remark role="version" condition="inherit"/> + </para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-update-updatename-doc_put"> + + <title><literal>PUT /db/_design/design-doc/_update/updatename/doc</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" + condition="db-design-designdoc-update-updatename-doc"/> + + <remark role="method" condition="PUT"/> + + <remark role="version" condition="inherit"/> + </para> + + </section> + + <section + id="couchdb-api-design_db-design-designdoc-update-updatename_post"> + + <title><literal>POST /db/_design/design-doc/_update/updatename</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" + condition="db-design-designdoc-update-updatename"/> + + <remark role="method" condition="POST"/> + + <remark role="version" condition="inherit"/> + </para> + + </section> + + <section + id="couchdb-api-design_db-design-designdoc-rewrite-rewritename-anything"> + + <title><literal>ALL + /db/_design/design-doc/_rewrite/rewrite-name/anything</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-design-designdoc-rewrite-rewritename-anything"/> + + <remark role="method" condition="ALL"/> + + <remark role="version" condition="inherit"/> + </para> + + </section> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/couchdb-api-introduction.xml b/share/docs/couchdb-manual-1.1/couchdb-api-introduction.xml new file mode 100644 index 000000000..714e5b0bb --- /dev/null +++ b/share/docs/couchdb-manual-1.1/couchdb-api-introduction.xml @@ -0,0 +1,851 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- -*- docbook-xml -*- --> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-api-basics"> + + <title>CouchDB API</title> + + <para> + The CouchDB API is the primary method of interfacing to a CouchDB + instance. Requests are made using HTTP and requests are used to + request information from the database, store new data, and perform + views and formatting of the information stored within the documents. + </para> + + <para> + Requests to the API can be categorised by the different areas of the + CouchDB system that you are accessing, and the HTTP method used to + send the request. Different methods imply different operations, for + example retrieval of information from the database is typically + handled by the <literal>GET</literal> operation, while updates are + handled by either a <literal>POST</literal> or + <literal>PUT</literal> request. There are some differences between + the information that must be supplied for the different methods. For + a guide to the basic HTTP methods and request structure, see + <xref linkend="couchdb-api-introduction-requests"/>. + </para> + + <para> + For nearly all operations, the submitted data, and the returned data + structure, is defined within a JavaScript Object Notation (JSON) + object. Basic information on the content and data types for JSON are + provided in <xref linkend="couchdb-api-introduction-json"/>. + </para> + + <para> + Errors when accessing the CouchDB API are reported using standard + HTTP Status Codes. A guide to the generic codes returned by CouchDB + are provided in + <xref linkend="couchdb-api-introduction-returncodes"/>. + </para> + + <para> + When accessing specific areas of the CouchDB API, specific + information and examples on the HTTP methods and request, JSON + structures, and error codes are provided. For a guide to the + different areas of the API, see + <xref + linkend="couchdb-api-overview"/>. + </para> + + <section id="couchdb-api-introduction-requests"> + + <title>Request Format and Responses</title> + + <para> + CouchDB supports the following HTTP request methods: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal>GET</literal> + </para> + + <para> + Request the specified item. As with normal HTTP requests, the + format of the URL defines what is returned. With CouchDB this + can include static items, database documents, and + configuration and statistical information. In most cases the + information is returned in the form of a JSON document. + </para> + </listitem> + + <listitem> + <para> + <literal>HEAD</literal> + </para> + + <para> + The <literal>HEAD</literal> method is used to get the HTTP + header of a <literal>GET</literal> request without the body of + the response. + </para> + </listitem> + + <listitem> + <para> + <literal>POST</literal> + </para> + + <para> + Upload data. Within CouchDB <literal>POST</literal> is used to + set values, including uploading documents, setting document + values, and starting certain administration commands. + </para> + </listitem> + + <listitem> + <para> + <literal>PUT</literal> + </para> + + <para> + Used to put a specified resource. In CouchDB + <literal>PUT</literal> is used to create new objects, + including databases, documents, views and design documents. + </para> + </listitem> + + <listitem> + <para> + <literal>DELETE</literal> + </para> + + <para> + Deletes the specified resource, including documents, views, + and design documents. + </para> + </listitem> + + <listitem> + <para> + <literal>COPY</literal> + </para> + + <para> + A special method that can be used to copy documents and + objects. + </para> + </listitem> + + </itemizedlist> + + <para> + If you use the an unsupported HTTP request type with a URL that + does not support the specified type, a 405 error will be returned, + listing the supported HTTP methods. For example: + </para> + +<programlisting> +{ + "error":"method_not_allowed", + "reason":"Only GET,HEAD allowed" +} + </programlisting> + +<!-- TODO: Link should be updated when we look at HTML return object --> + + <para> + The CouchDB design document API and the functions when returning + HTML (for example as part of a show or list) enables you to + include custom HTTP headers through the <literal>headers</literal> + block of the return object. For more information, see + <xref linkend="couchdb-api-functional"/>. + </para> + + </section> + + <section id="couchdb-api-introduction-request-header"> + + <title>HTTP Headers</title> + + <para> + Because CouchDB uses HTTP for all communication, you need to + ensure that the correct HTTP headers are supplied (and processed + on retrieval) so that you get the right format and encoding. + Different environments and clients will be more or less strict on + the effect of these HTTP headers (especially when not present). + Where possible you should be as specific as possible. + </para> + + <section id="couchdb-api-introduction-request-header-request"> + + <title>Request Headers</title> + + <itemizedlist> + + <listitem> + <para> + <literal>Content-type</literal> + </para> + + <para> + Specifies the content type of the information being supplied + within the request. The specification uses MIME type + specifications. For the majority of requests this will be + JSON (<literal>application/json</literal>). For some + settings the MIME type will be plain text. When uploading + attachments it should be the corresponding MIME type for the + attachment or binary + (<literal>application/octet-stream</literal>). + </para> + + <para> + The use of the <literal>Content-type</literal> on a request + is highly recommended. + </para> + </listitem> + + <listitem> + <para> + <literal>Accept</literal> + </para> + + <para> + Specifies the list of accepted data types to be returned by + the server (i.e. that are accepted/understandable by the + client). The format should be a list of one or more MIME + types, separated by colons. + </para> + + <para> + For the majority of requests the definition should be for + JSON data (<literal>application/json</literal>). For + attachments you can either specify the MIME type explicitly, + or use <literal>*/*</literal> to specify that all file types + are supported. If the <literal>Accept</literal> header is + not supplied, then the <literal>*/*</literal> MIME type is + assumed (i.e. client accepts all formats). + </para> + + <para> + The use of <literal>Accept</literal> in queries for CouchDB + is not required, but is highly recommended as it helps to + ensure that the data returned can be processed by the + client. + </para> + + <para> + If you specify a data type using the + <literal>Accept</literal> header, CouchDB will honor the + specified type in the <literal>Content-type</literal> header + field returned. For example, if you explicitly request + <literal>application/json</literal> in the + <literal>Accept</literal> of a request, the returned HTTP + headers will use the value in the returned + <literal>Content-type</literal> field. + </para> + + <para> + For example, when sending a request without an explicit + <literal>Accept</literal> header, or when specifying + <literal>*/*</literal>: + </para> + +<programlisting> +GET /recipes HTTP/1.1 +Host: couchdb:5984 +Accept: */* +</programlisting> + + <para> + The returned headers are: + </para> + +<programlisting> +Server: CouchDB/1.0.1 (Erlang OTP/R13B) +Date: Thu, 13 Jan 2011 13:39:34 GMT +Content-Type: text/plain;charset=utf-8 +Content-Length: 227 +Cache-Control: must-revalidate +</programlisting> + + <para> + Note that the returned content type is + <literal>text/plain</literal> even though the information + returned by the request is in JSON format. + </para> + + <para> + Explicitly specifying the <literal>Accept</literal> header: + </para> + +<programlisting> +GET /recipes HTTP/1.1 +Host: couchdb:5984 +Accept: application/json +</programlisting> + + <para> + The headers returned include the + <literal>application/json</literal> content type: + </para> + +<programlisting> +Server: CouchDB/1.0.1 (Erlang OTP/R13B) +Date: Thu, 13 Jan 2011 13:40:11 GMT +Content-Type: application/json +Content-Length: 227 +Cache-Control: must-revalidate +</programlisting> + </listitem> + + </itemizedlist> + + </section> + + <section id="couchdb-api-introduction-request-header-response"> + + <title>Response Headers</title> + + <para> + Response headers are returned by the server when sending back + content and include a number of different header fields, many of + which are standard HTTP response header and have no significance + to CouchDB operation. The list of response headers important to + CouchDB are listed below. + </para> + + <itemizedlist> + + <listitem> + <para> + <literal>Content-type</literal> + </para> + + <para> + Specifies the MIME type of the returned data. For most + request, the returned MIME type is + <literal>text/plain</literal>. All text is encoded in + Unicode (UTF-8), and this is explicitly stated in the + returned <literal>Content-type</literal>, as + <literal>text/plain;charset=utf-8</literal>. + </para> + </listitem> + + <listitem> + <para> + <literal>Cache-control</literal> + </para> + + <para> + The cache control HTTP response header provides a suggestion + for client caching mechanisms on how to treat the returned + information. CouchDB typically returns the + <literal>must-revalidate</literal>, which indicates that the + information should be revalidated if possible. This is used + to ensure that the dynamic nature of the content is + correctly updated. + </para> + </listitem> + + <listitem> + <para> + <literal>Content-length</literal> + </para> + + <para> + The length (in bytes) of the returned content. + </para> + </listitem> + + <listitem> + <para> + <literal>Etag</literal> + </para> + + <para> + The <literal>Etag</literal> HTTP header field is used to + show the revision for a document. + </para> + </listitem> + + </itemizedlist> + + </section> + + </section> + + <section id="couchdb-api-introduction-json"> + + <title>JSON Basics</title> + + <para> + The majority of requests and responses to CouchDB use the + JavaScript Object Notation (JSON) for formatting the content and + structure of the data and responses. + </para> + + <para> + JSON is used because it is the simplest and easiest to use + solution for working with data within a web browser, as JSON + structures can be evaluated and used as JavaScript objects within + the web browser environment. JSON also integrates with the + server-side JavaScript used within CouchDB. + </para> + + <para> + JSON supports the same basic types as supported by JavaScript, + these are: + </para> + + <itemizedlist> + + <listitem> + <para> + Number (either integer or floating-point). + </para> + </listitem> + + <listitem> + <para> + String; this should be enclosed by double-quotes and supports + Unicode characters and backslash escaping. For example: + </para> + +<programlisting>"A String"</programlisting> + </listitem> + + <listitem> + <para> + Boolean - a <literal>true</literal> or + <literal>false</literal> value. You can use these strings + directly. For example: + </para> + +<programlisting>{ "value": true}</programlisting> + </listitem> + + <listitem> + <para> + Array - a list of values enclosed in square brackets. For + example: + </para> + +<programlisting>["one", "two", "three"]</programlisting> + </listitem> + + <listitem> + <para> + Object - a set of key/value pairs (i.e. an associative array, + or hash). The key must be a string, but the value can be any + of the supported JSON values. For example: + </para> + +<programlisting> +{ + "servings" : 4, + "subtitle" : "Easy to make in advance, and then cook when ready", + "cooktime" : 60, + "title" : "Chicken Coriander" +} + </programlisting> + + <para> + In CouchDB, the JSON object is used to represent a variety of + structures, including the main CouchDB document. + </para> + </listitem> + + </itemizedlist> + + <para> + Parsing JSON into a JavaScript object is supported through the + <literal>eval()</literal> function in JavaScript, or through + various libraries that will perform the parsing of the content + into a JavaScript object for you. Libraries for parsing and + generating JSON are available in many languages, including Perl, + Python, Ruby, Erlang and others. + </para> + + <warning> + <para> + Care should be taken to ensure that your JSON structures are + valid, invalid structures will cause CouchDB to return an HTTP + status code of 500 (server error). See + <xref + linkend="couchdb-api-introduction-returncode-500"/> + . + </para> + </warning> + + </section> + + <section id="couchdb-api-introduction-returncodes"> + + <title>HTTP Status Codes</title> + + <para> + With the interface to CouchDB working through HTTP, error codes + and statuses are reported using a combination of the HTTP status + code number, and corresponding data in the body of the response + data. + </para> + + <para> + A list of the error codes returned by CouchDB, and generic + descriptions of the related errors are provided below. The meaning + of different status codes for specific request types are provided + in the corresponding API call reference. + </para> + + <itemizedlist> + + <listitem> + <para id="couchdb-api-introduction-returncode-200"> + <literal>200 - OK</literal> + </para> + + <para> + Request completed successfully. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-201"> + <literal>201 - Created</literal> + </para> + + <para> + Document created successfully. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-202"> + <literal>202 - Accepted</literal> + </para> + + <para> + Request has been accepted, but the corresponding operation may + not have completed. This is used for background operations, + such as database compaction. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-304"> + <literal>304 - Not Modified</literal> + </para> + + <para> + The additional content requested has not been modified. This + is used with the ETag system to identify the version of + information returned. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-400"> + <literal>400 - Bad Request</literal> + </para> + + <para> + Bad request structure. The error can indicate an error with + the request URL, path or headers. Differences in the supplied + MD5 hash and content also trigger this error, as this may + indicate message corruption. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-401"> + <literal>401 - Unauthorized</literal> + </para> + + <para> + The item requested was not available using the supplied + authorization, or authorization was not supplied. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-403"> + <literal>403 - Forbidden</literal> + </para> + + <para> + The requested item or operation is forbidden. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-404"> + <literal>404 - Not Found</literal> + </para> + + <para> + The requested content could not be found. The content will + include further information, as a JSON object, if available. + The structure will contain two keys, <literal>error</literal> + and <literal>reason</literal>. For example: + </para> + +<programlisting>{"error":"not_found","reason":"no_db_file"}</programlisting> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-405"> + <literal>405 - Resource Not Allowed</literal> + </para> + + <para> + A request was made using an invalid HTTP request type for the + URL requested. For example, you have requested a + <literal>PUT</literal> when a <literal>POST</literal> is + required. Errors of this type can also triggered by invalid + URL strings. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-406"> + <literal>406 - Not Acceptable</literal> + </para> + + <para> + The requested content type is not supported by the server. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-409"> + <literal>409 - Conflict</literal> + </para> + + <para> + Request resulted in an update conflict. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-412"> + <literal>412 - Precondition Failed</literal> + </para> + + <para> + The request headers from the client and the capabilities of + the server do not match. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-415"> + <literal>415 - Bad Content Type</literal> + </para> + + <para> + The content types supported, and the content type of the + information being requested or submitted indicate that the + content type is not supported. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-416"> + <literal>416 - Requested Range Not Satisfiable</literal> + </para> + + <para> + The range specified in the request header cannot be satisfied + by the server. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-417"> + <literal>417 - Expectation Failed</literal> + </para> + + <para> + When sending documents in bulk, the bulk load operation + failed. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-500" xreflabel="HTTP + Status Code 500"> + <literal>500 - Internal Server Error</literal> + </para> + + <para> + The request was invalid, either because the supplied JSON was + invalid, or invalid information was supplied as part of the + request. + </para> + </listitem> + + </itemizedlist> + + </section> + + <section id="couchdb-api-overview"> + + <title>CouchDB API Overview</title> + + <para> + The components of the API URL path help determine the part of the + CouchDB server that is being accessed. The result is the structure + of the URL request both identifies and effectively describes the + area of the database you are accessing. + </para> + + <para> + As with all URLs, the individual components are separated by a + forward slash. + </para> + + <para> + As a general rule, URL components and JSON fields starting with + the <literal>_</literal> (underscore) character represent a + special component or entity within the server or returned object. + For example, the URL fragment <literal>/_all_dbs</literal> gets a + list of all of the databases in a CouchDB instance. + </para> + + <para> + The remainder of the URL API structure can be divided up according + to the URL structure. The different sections are divided as + follows: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal>/db</literal> + </para> + + <para> + Database methods, related to adding, updating or deleting + databases, and setting database parameters and operations. For + more detailed information, see + <xref + linkend="couchdb-api-db"/> . + </para> + </listitem> + + <listitem> + <para> + <literal>/db/doc</literal> + </para> + + <para> + Document methods, those that create, store, update or delete + CouchDB documents and their attachments. For more information, + see <xref + linkend="couchdb-api-dbdoc"/>. + </para> + </listitem> + + <listitem> + <para> + <literal>/db/_local/local-doc</literal> + </para> + + <para> + Document methods, those that create, store, update or delete + CouchDB documents only within the local database. Local + documents are not synchronized with other databases. For more + information, see + <xref + linkend="couchdb-api-localdb"/>. + </para> + </listitem> + + <listitem> + <para> + <literal>/db/_design/design-doc</literal> + </para> + + <para> + Design documents provide the methods and structure for + recovering information from a CouchDB database in the form of + views, shows and lists. For more information, see + <xref + linkend="couchdb-api-design"/>. + </para> + </listitem> + + <listitem> + <para> + <literal>/_special</literal> + </para> + + <para> + Special methods that obtain or set information about the + CouchDB instance, including methods for configuring + replication, accessing the logs, and generate Universally + Unique IDs (UUIDs). For more information, see + <xref + linkend="couchdb-api-misc"/>. + </para> + </listitem> + + <listitem> + <para> + <literal>/_config</literal> + </para> + + <para> + Methods for getting, and settings, CouchDB configuration + parameters. For more information, see + <xref + linkend="couchdb-api-misc"/>. + </para> + </listitem> + + </itemizedlist> + +<!-- + Databases and Documents + + To see a listing of databases: + + /_all_dbs + To see some basic information about a database: + + /dbname/ + To see all a listing of the data documents in a database: + + /dbname/_all_docs + To see a document: + + /dbname/docid + To download a file attachment: + + /dbname/docid/filename + Design Documents and Views + + To see a design document: + + /dbname/_design/designdocname + To query a view. + + /dbname/_design/designdocname/_view/viewname?query + NOTE: Apparently the structure depends on the version #. In 0.8.1 the above doesn't work, but the below works: - JohnWarden + + /dbname/_view/designdocname/viewname?query + To query a temporary ("slow") view (with the custom view function in the body of the request): + + /dbname/_temp_view?query + Formatting + + To format a document through a "show" template: + + /dbname/_design/designdocname/_show/showname/docid + To format a view through a "list" template: + + /dbname/_design/designdocname/_list/listname/viewname?query + --> + + </section> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/couchdb-api-json-metasrc.xml b/share/docs/couchdb-manual-1.1/couchdb-api-json-metasrc.xml new file mode 100644 index 000000000..7f8d86e93 --- /dev/null +++ b/share/docs/couchdb-manual-1.1/couchdb-api-json-metasrc.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE appendix PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<appendix id="couchdb-api-json"> + + <title>JSON Structure Reference</title> + + <para> + The following appendix provides a quick reference to all the JSON + structures that you can supply to CouchDB, or get in return to + requests. + </para> + + <para role="meta" id="table-couchdb-api-json-summary"> + <remark role="title">JSON Structures</remark> + + <remark role="type" condition="json"/> + + <remark role="src" condition="json"/> + + <remark role="output" condition="summarytable"/> + + <remark role="version" condition="inherit"/> + + <remark role="idprefix" condition="table-couchdb-api-json"/> + </para> + + <para role="meta"> + <remark role="type" condition="json"/> + + <remark role="src" condition="json"/> + + <remark role="output" condition="alltables"/> + + <remark role="version" condition="inherit"/> + + <remark role="idprefix" condition="table-couchdb-api-json"/> + </para> + +</appendix> diff --git a/share/docs/couchdb-manual-1.1/couchdb-api-localdb-metasrc.xml b/share/docs/couchdb-manual-1.1/couchdb-api-localdb-metasrc.xml new file mode 100644 index 000000000..6bbd0f016 --- /dev/null +++ b/share/docs/couchdb-manual-1.1/couchdb-api-localdb-metasrc.xml @@ -0,0 +1,186 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-api-localdb"> + + <title>CouchDB API Server Local (non-replicating) Document Methods</title> + + <para> + The Local (non-replicating) document interface allows you to create + local documents that are not replicated to other databases. These + documents can be used to hold configuration or other information + that is required specifically on the local CouchDB instance. + </para> + + <para> + Local documents have the following limitations: + </para> + + <itemizedlist> + + <listitem> + <para> + Local documents are not replicated to other databases. + </para> + </listitem> + + <listitem> + <para> + The ID of the local document must be known for the document to + accessed. You cannot obtain a list of local documents from the + database. + </para> + </listitem> + + <listitem> + <para> + Local documents are not output by views, or the + <literal>_all_docs</literal> view. + </para> + </listitem> + + </itemizedlist> + + <para> + Local documents can be used when you want to store configuration or + other information for the curent (local) instance of a given + database. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <para role="meta" id="table-couchdb-api-localdb-summary"> + <remark role="title">Local (non-replicating) Document API + Calls</remark> + + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="summarytable"/> + + <remark role="filter_class" condition="localdb"/> + + <remark role="version" condition="inherit"/> + + <remark role="idprefix" condition="couchdb-api-localdb"/> + </para> + + <section id="couchdb-api-localdb_db-local-localdoc_get"> + + <title><literal>GET /db/_local/local-doc</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-local-localdoc"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Gets the specified local document. The semantics are identical to + accessing a standard document in the specified database, except + that the document is not replicated. See + <xref + linkend="couchdb-api-dbdoc_db-doc_get"/>. + </para> + + </section> + + <section id="couchdb-api-localdb_db-local-localdoc_put"> + + <title><literal>PUT /db/_local/local-doc</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-local-localdoc"/> + + <remark role="method" condition="PUT"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Stores the specified local document. The semantics are identical + to storing a standard document in the specified database, except + that the document is not replicated. See + <xref + linkend="couchdb-api-dbdoc_db-doc_put"/>. + </para> + + </section> + + <section id="couchdb-api-localdb_db-local-localdoc_delete"> + + <title><literal>DELETE /db/_local/local-doc</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-local-localdoc"/> + + <remark role="method" condition="DELETE"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Deletes the specified local document. The semantics are identical + to deleting a standard document in the specified database, except + that the document is not replicated. See + <xref + linkend="couchdb-api-dbdoc_db-doc_delete"/>. + </para> + + </section> + + <section id="couchdb-api-localdb_db-local-localdoc_copy"> + + <title><literal>COPY /db/_local/local-doc</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="db-local-localdoc"/> + + <remark role="method" condition="COPY"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Copies the specified local document. The semantics are identical + to copying a standard document in the specified database, except + that the document is not replicated. See + <xref + linkend="couchdb-api-dbdoc_db-doc_copy"/>. + </para> + + </section> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/couchdb-api-misc-metasrc.xml b/share/docs/couchdb-manual-1.1/couchdb-api-misc-metasrc.xml new file mode 100644 index 000000000..200749fab --- /dev/null +++ b/share/docs/couchdb-manual-1.1/couchdb-api-misc-metasrc.xml @@ -0,0 +1,1357 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-api-misc"> + + <title>CouchDB API Server Miscellaneous Methods</title> + + <para> + The CouchDB Miscellaneous interface provides the basic interface to + a CouchDB server for obtaining CouchDB information and getting and + setting configuration information. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <para role="meta" id="table-couchdb-api-misc-summary"> + <remark role="title">Miscellaneous API Calls</remark> + + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="summarytable"/> + + <remark role="filter_class" condition="misc"/> + + <remark role="version" condition="inherit"/> + + <remark role="idprefix" condition="couchdb-api-misc"/> + </para> + + <section id="couchdb-api-misc_root_get"> + + <title><literal>GET /</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="root"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Accessing the root of a CouchDB instance returns meta information + about the instance. The response is a JSON structure containing + information about the server, including a welcome message and the + version of the server. + </para> + +<programlisting> +{ + "couchdb" : "Welcome", + "version" : "1.0.1" +} +</programlisting> + + </section> + + <section id="couchdb-api-misc_active-tasks_get"> + + <title><literal>GET /_active_tasks</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="active-tasks"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + You can obtain a list of active tasks by using the + <literal>/_active_tasks</literal> URL. The result is a JSON array + of the currently running tasks, with each task being described + with a single object. For example: + </para> + +<programlisting> + +<![CDATA[ +[ + { + "pid" : "<0.11599.0>", + "status" : "Copied 0 of 18369 changes (0%)", + "task" : "recipes", + "type" : "Database Compaction" + } +] +]]> + + </programlisting> + + <para> + The returned structure includes the following fields for each + task: + </para> + + <para role="meta" id="table-couchdb-api-misc-active-tasks-json"> + <remark role="type" condition="json"/> + + <remark role="src" condition="json"/> + + <remark role="output" condition="itemtable"/> + + <remark role="itemid" condition="activetasks"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + For operation type, valid values include: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal>Database Compaction</literal> + </para> + </listitem> + + <listitem> + <para> + <literal>Replication</literal> + </para> + </listitem> + + <listitem> + <para> + <literal>View Group Compaction</literal> + </para> + </listitem> + + <listitem> + <para> + <literal>View Group Indexer</literal> + </para> + </listitem> + + </itemizedlist> + + </section> + + <section id="couchdb-api-misc_all-dbs_get"> + + <title><literal>GET /_all_dbs</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="all-dbs"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Returns a list of all the databases in the CouchDB instance. For + example: + </para> + +<programlisting> +GET http://couchdb:5984/_all_dbs +Accept: application/json +</programlisting> + + <para> + The return is a JSON array: + </para> + +<programlisting> +[ + "_users", + "contacts", + "docs", + "invoices", + "locations" +] + +</programlisting> + + </section> + + <section id="couchdb-api-misc_log_get"> + + <title><literal>GET /_log</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="log"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Gets the CouchDB log, equivalent to accessing the local log file + of the corresponding CouchDB instance. + </para> + + <para> + When you request the log, the response is returned as plain + (UTF-8) text, with an HTTP <literal>Content-type</literal> header + as <literal>text/plain</literal>. + </para> + + <para> + For example, the request: + </para> + +<programlisting> +GET http://couchdb:5984/_log +Accept: */* +</programlisting> + + <para> + The raw text is returned: + </para> + +<programlisting> +<![CDATA[ +[Wed, 27 Oct 2010 10:49:42 GMT] [info] [<0.23338.2>] 192.168.0.2 - - 'PUT' /authdb 401 + +[Wed, 27 Oct 2010 11:02:19 GMT] [info] [<0.23428.2>] 192.168.0.116 - - 'GET' /recipes/FishStew 200 + +[Wed, 27 Oct 2010 11:02:19 GMT] [info] [<0.23428.2>] 192.168.0.116 - - 'GET' /_session 200 + +[Wed, 27 Oct 2010 11:02:19 GMT] [info] [<0.24199.2>] 192.168.0.116 - - 'GET' / 200 + +[Wed, 27 Oct 2010 13:03:38 GMT] [info] [<0.24207.2>] 192.168.0.116 - - 'GET' /_log?offset=5 200 +]]> +</programlisting> + + <para> + If you want to pick out specific parts of the log information you + can use the <literal>bytes</literal> argument, which specifies the + number of bytes to be returned, and <literal>offset</literal>, + which specifies where the reading of the log should start, counted + back from the end. For example, if you use the following request: + </para> + +<programlisting> +GET /_log?bytes=500&offset=2000 +</programlisting> + + <para> + Reading of the log will start at 2000 bytes from the end of the + log, and 500 bytes will be shown. + </para> + + </section> + + <section id="couchdb-api-misc_replicate_post"> + + <title><literal>POST /_replicate</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="replicate"/> + + <remark role="method" condition="POST"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Request, configure, or stop, a replication operation. + </para> + + <para> + The specification of the replication request is controlled through + the JSON content of the request. The JSON should be an object with + the fields defining the source, target and other options. The + fields of the JSON request are shown in the table below: + </para> + + <para role="meta" id="table-couchdb-api-misc-json-replication"> + <remark role="type" condition="json"/> + + <remark role="src" condition="json"/> + + <remark role="output" condition="itemtable"/> + + <remark role="itemid" condition="replication"/> + + <remark role="version" condition="inherit"/> + </para> + + <section id="couchdb-api-misc_replicate_post-operation"> + + <title>Replication Operation</title> + + <para> + The aim of the replication is that at the end of the process, + all active documents on the source database are also in the + destination database and all documents that were deleted in the + source databases are also deleted (if they exist) on the + destination database. + </para> + + <para> + Replication can be described as either push or pull replication: + </para> + + <itemizedlist> + + <listitem> + <para> + <emphasis>Pull replication</emphasis> is where the + <literal>source</literal> is the remote CouchDB instance, + and the <literal>destination</literal> is the local + database. + </para> + + <para> + Pull replication is the most useful solution to use if your + source database has a permanent IP address, and your + destination (local) database may have a dynamically assigned + IP address (for example, through DHCP). This is particularly + important if you are replicating to a mobile or other device + from a central server. + </para> + </listitem> + + <listitem> + <para> + <emphasis>Push replication</emphasis> is where the + <literal>source</literal> is a local database, and + <literal>destination</literal> is a remote database. + </para> + </listitem> + + </itemizedlist> + + </section> + + <section id="couchdb-api-misc_replicate_post-sourcetarget"> + + <title>Specifying the Source and Target Database</title> + + <para> + You must use the URL specification of the CouchDB database if + you want to perform replication in either of the following two + situations: + </para> + + <itemizedlist> + + <listitem> + <para> + Replication with a remote database (i.e. another instance of + CouchDB on the same host, or a different host) + </para> + </listitem> + + <listitem> + <para> + Replication with a database that requires authentication + </para> + </listitem> + + </itemizedlist> + + <para> + For example, to request replication between a database local to + the CouchDB instance to which you send the request, and a remote + database you might use the following request: + </para> + +<programlisting> +POST http://couchdb:5984/_replicate +Content-Type: application/json +Accept: application/json + +{ + "source" : "recipes", + "target" : "http://coucdb-remote:5984/recipes", +} + </programlisting> + + <para> + In all cases, the requested databases in the + <literal>source</literal> and <literal>target</literal> + specification must exist. If they do not, an error will be + returned within the JSON object: + </para> + +<programlisting> +{ + "error" : "db_not_found" + "reason" : "could not open http://couchdb-remote:5984/ol1ka/", +} + </programlisting> + + <para> + You can create the target database (providing your user + credentials allow it) by adding the + <literal>create_target</literal> field to the request object: + </para> + +<programlisting> +POST http://couchdb:5984/_replicate +Content-Type: application/json +Accept: application/json + +{ + "create_target" : true + "source" : "recipes", + "target" : "http://couchdb-remote:5984/recipes", +} +</programlisting> + + <para> + The <literal>create_target</literal> field is not destructive. + If the database already exists, the replication proceeds as + normal. + </para> + + </section> + + <section id="couchdb-api-misc_replicate_post-single"> + + <title>Single Replication</title> + + <para> + You can request replication of a database so that the two + databases can be synchronized. By default, the replication + process occurs one time and synchronizes the two databases + together. For example, you can request a single synchronization + between two databases by supplying the <literal>source</literal> + and <literal>target</literal> fields within the request JSON + content. + </para> + +<programlisting> +POST http://couchdb:5984/_replicate +Content-Type: application/json +Accept: application/json + +{ + "source" : "recipes", + "target" : "recipes-snapshot", +} +</programlisting> + + <para> + In the above example, the databases <literal>recipes</literal> + and <literal>recipes-snapshot</literal> will be synchronized. + These databases are local to the CouchDB instance where the + request was made. The response will be a JSON structure + containing the success (or failure) of the synchronization + process, and statistics about the process: + </para> + +<programlisting> +{ + "ok" : true, + "history" : [ + { + "docs_read" : 1000, + "session_id" : "52c2370f5027043d286daca4de247db0", + "recorded_seq" : 1000, + "end_last_seq" : 1000, + "doc_write_failures" : 0, + "start_time" : "Thu, 28 Oct 2010 10:24:13 GMT", + "start_last_seq" : 0, + "end_time" : "Thu, 28 Oct 2010 10:24:14 GMT", + "missing_checked" : 0, + "docs_written" : 1000, + "missing_found" : 1000 + } + ], + "session_id" : "52c2370f5027043d286daca4de247db0", + "source_last_seq" : 1000 +} +</programlisting> + + <para> + The structure defines the replication status, as described in + the table below: + </para> + + <para role="meta" id="table-couchdb-api-misc-json-replication-status"> + <remark role="type" condition="json"/> + + <remark role="src" condition="json"/> + + <remark role="output" condition="itemtable"/> + + <remark role="itemid" condition="replication-status"/> + + <remark role="version" condition="inherit"/> + </para> + + </section> + + <section id="couchdb-api-misc_replicate_post-continuous"> + + <title>Continuous Replication</title> + + <para> + Synchronization of a database with the previously noted methods + happens only once, at the time the replicate request is made. To + have the target database permanently replicated from the source, + you must set the <literal>continuous</literal> field of the JSON + object within the request to true. + </para> + + <para> + With continuous replication changes in the source database are + replicated to the target database in perpetuity until you + specifically request that replication ceases. + </para> + +<programlisting> +POST http://couchdb:5984/_replicate +Content-Type: application/json +Accept: application/json + +{ + "continuous" : true + "source" : "recipes", + "target" : "http://couchdb-remote:5984/recipes", +} +</programlisting> + + <para> + Changes will be replicated between the two databases as long as + a network connection is available between the two instances. + </para> + + <note> + <para> + Two keep two databases synchronized with each other, you need + to set replication in both directions; that is, you must + replicate from <literal>databasea</literal> to + <literal>databaseb</literal>, and separately from + <literal>databaseb</literal> to <literal>databasea</literal>. + </para> + </note> + + </section> + + <section id="couchdb-api-misc_replicate_post-cancel"> + + <title>Canceling Continuous Replication</title> + + <para> + You can cancel continuous replication by adding the + <literal>cancel</literal> field to the JSON request object and + setting the value to true. Note that the structure of the + request must be identical to the original for the cancelation + request to be honoured. For example, if you requested continuous + replication, the cancellation request must also contain the + <literal>continuous</literal> field. + </para> + + <para> + For example, the replication request: + </para> + +<programlisting> +POST http://couchdb:5984/_replicate +Content-Type: application/json +Accept: application/json + +{ + "source" : "recipes", + "target" : "http://couchdb-remote:5984/recipes", + "create_target" : true, + "continuous" : true +} +</programlisting> + + <para> + Must be canceled using the request: + </para> + +<programlisting> +POST http://couchdb:5984/_replicate +Content-Type: application/json +Accept: application/json + +{ + "cancel" : true, + "continuous" : true + "create_target" : true, + "source" : "recipes", + "target" : "http://couchdb-remote:5984/recipes", +} +</programlisting> + + <para> + Requesting cancellation of a replication that does not exist + results in a 404 error. + </para> + + </section> + + </section> + + <section id="couchdb-api-misc_restart_post"> + + <title><literal>POST /_restart</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="restart"/> + + <remark role="method" condition="POST"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Restarts the CouchDB instance. You must be authenticated as a user + with administration privileges for this to work. + </para> + + <para> + For example: + </para> + +<programlisting> +POST http://admin:password@couchdb:5984/_restart +</programlisting> + + <para> + The return value (if the server has not already restarted) is a + JSON status object indicating that the request has been received: + </para> + +<programlisting> +{ + "ok" : true, +} +</programlisting> + + <para> + If the server has already restarted, the header may be returned, + but no actual data is contained in the response. + </para> + + </section> + + <section id="couchdb-api-misc_stats_get"> + + <title><literal>GET /_stats</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="stats"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + The <literal>_stats</literal> method returns a JSON object + containting the statistics for the running server. The object is + structured with top-level sections collating the statistics for a + range of entries, with each individual statistic being easily + identified, and the content of each statistic is self-describing. + For example, the request time statistics, within the + <literal>couchdb</literal> section are structured as follows: + </para> + +<programlisting> +{ + "couchdb" : { +... + "request_time" : { + "stddev" : "27.509", + "min" : "0.333333333333333", + "max" : "152", + "current" : "400.976", + "mean" : "10.837", + "sum" : "400.976", + "description" : "length of a request inside CouchDB without MochiWeb" + }, +... + } +} + </programlisting> + + <para> + The fields provide the current, minimum and maximum, and a + collection of statistical means and quantities. The quantity in + each case is not defined, but the descriptions below provide + </para> + + <para> + The statistics are divided into the following top-level sections: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal>couchdb</literal> + </para> + + <para> + Describes statistics specific to the internals of CouchDB. + </para> + + <table> + <title><literal>couchdb</literal> statistics</title> + <tgroup cols="3"> + <colspec colname="stat"/> + <colspec colname="desc"/> + <colspec colname="unit"/> + <thead> + <row> + <entry> + Statistic ID + </entry> + <entry> + Description + </entry> + <entry> + Unit + </entry> + </row> + </thead> + <tbody> + <row> + <entry><literal>auth_cache_hits</literal> + </entry> + <entry> + Number of authentication cache hits + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>auth_cache_misses</literal> + </entry> + <entry> + Number of authentication cache misses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>database_reads</literal> + </entry> + <entry> + Number of times a document was read from a database + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>database_writes</literal> + </entry> + <entry> + Number of times a database was changed + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>open_databases</literal> + </entry> + <entry> + Number of open databases + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>open_os_files</literal> + </entry> + <entry> + Number of file descriptors CouchDB has open + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>request_time</literal> + </entry> + <entry> + Length of a request inside CouchDB without MochiWeb + </entry> + <entry> + milliseconds + </entry> + </row> + </tbody> + </tgroup> + </table> + </listitem> + + <listitem> + <para> + <literal>httpd_request_methods</literal> + </para> + + <table> + <title><literal>httpd_request_methods</literal> statistics</title> + <tgroup cols="3"> + <colspec colname="stat"/> + <colspec colname="desc"/> + <colspec colname="unit"/> + <thead> + <row> + <entry> + Statistic ID + </entry> + <entry> + Description + </entry> + <entry> + Unit + </entry> + </row> + </thead> + <tbody> + <row> + <entry><literal>COPY</literal> + </entry> + <entry> + Number of HTTP COPY requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>DELETE</literal> + </entry> + <entry> + Number of HTTP DELETE requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>GET</literal> + </entry> + <entry> + Number of HTTP GET requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>HEAD</literal> + </entry> + <entry> + Number of HTTP HEAD requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>POST</literal> + </entry> + <entry> + Number of HTTP POST requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>PUT</literal> + </entry> + <entry> + Number of HTTP PUT requests + </entry> + <entry> + number + </entry> + </row> + </tbody> + </tgroup> + </table> + </listitem> + + <listitem> + <para> + <literal>httpd_status_codes</literal> + </para> + + <table> + <title><literal>httpd_status_codes</literal> statistics</title> + <tgroup cols="3"> + <colspec colname="stat"/> + <colspec colname="desc"/> + <colspec colname="unit"/> + <thead> + <row> + <entry> + Statistic ID + </entry> + <entry> + Description + </entry> + <entry> + Unit + </entry> + </row> + </thead> + <tbody> + <row> + <entry><literal>200</literal> + </entry> + <entry> + Number of HTTP 200 OK responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>201</literal> + </entry> + <entry> + Number of HTTP 201 Created responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>202</literal> + </entry> + <entry> + Number of HTTP 202 Accepted responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>301</literal> + </entry> + <entry> + Number of HTTP 301 Moved Permanently responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>304</literal> + </entry> + <entry> + Number of HTTP 304 Not Modified responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>400</literal> + </entry> + <entry> + Number of HTTP 400 Bad Request responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>401</literal> + </entry> + <entry> + Number of HTTP 401 Unauthorized responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>403</literal> + </entry> + <entry> + Number of HTTP 403 Forbidden responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>404</literal> + </entry> + <entry> + Number of HTTP 404 Not Found responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>405</literal> + </entry> + <entry> + Number of HTTP 405 Method Not Allowed responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>409</literal> + </entry> + <entry> + Number of HTTP 409 Conflict responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>412</literal> + </entry> + <entry> + Number of HTTP 412 Precondition Failed responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>500</literal> + </entry> + <entry> + Number of HTTP 500 Internal Server Error responses + </entry> + <entry> + number + </entry> + </row> + </tbody> + </tgroup> + </table> + </listitem> + + <listitem> + <para> + <literal>httpd</literal> + </para> + + <table> + <title><literal>httpd</literal> statistics</title> + <tgroup cols="3"> + <colspec colname="stat"/> + <colspec colname="desc"/> + <colspec colname="unit"/> + <thead> + <row> + <entry> + Statistic ID + </entry> + <entry> + Description + </entry> + <entry> + Unit + </entry> + </row> + </thead> + <tbody> + <row> + <entry><literal>bulk_requests</literal> + </entry> + <entry> + Number of bulk requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>clients_requesting_changes</literal> + </entry> + <entry> + Number of clients for continuous _changes + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>requests</literal> + </entry> + <entry> + Number of HTTP requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>temporary_view_reads</literal> + </entry> + <entry> + Number of temporary view reads + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>view_reads</literal> + </entry> + <entry> + Number of view reads + </entry> + <entry> + number + </entry> + </row> + </tbody> + </tgroup> + </table> + </listitem> + + </itemizedlist> + + <para> + You can also access individual statistics by quoting the + statistics sections and statistic ID as part of the URL path. For + example, to get the <literal>request_time</literal> statistics, + you can use: + </para> + +<programlisting> +GET /_stats/couchdb/request_time + </programlisting> + + <para> + This returns an entire statistics object, as with the full + request, but containining only the request individual statistic. + Hence, the returned structure is as follows: + </para> + +<programlisting> +{ + "couchdb" : { + "request_time" : { + "stddev" : 7454.305, + "min" : 1, + "max" : 34185, + "current" : 34697.803, + "mean" : 1652.276, + "sum" : 34697.803, + "description" : "length of a request inside CouchDB without MochiWeb" + } + } +} + </programlisting> + + </section> + + <section id="couchdb-api-misc_utils_get"> + + <title><literal>GET /_utils</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="utils"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Accesses the built-in Futon administration interface for CouchDB. + </para> + + </section> + + <section id="couchdb-api-misc_uuids_get"> + + <title><literal>GET /_uuids</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="uuids"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Requests one or more Universally Unique Identifiers (UUIDs) from + the CouchDB instance. The response is a JSON object providing a + list of UUIDs. For example: + </para> + +<programlisting> +{ + "uuids" : [ + "7e4b5a14b22ec1cf8e58b9cdd0000da3" + ] +} +</programlisting> + + <para> + You can use the <literal>count</literal> argument to specify the + number of UUIDs to be returned. For example: + </para> + +<programlisting> + GET http://couchdb:5984/_uuids?count=5 +</programlisting> + + <para> + Returns: + </para> + +<programlisting> +{ + "uuids" : [ + "c9df0cdf4442f993fc5570225b405a80", + "c9df0cdf4442f993fc5570225b405bd2", + "c9df0cdf4442f993fc5570225b405e42", + "c9df0cdf4442f993fc5570225b4061a0", + "c9df0cdf4442f993fc5570225b406a20" + ] +} +</programlisting> + + <para> + The UUID type is determined by the UUID type setting in the + CouchDB configuration. See + <xref linkend="couchdb-api-config_config-section-key_put"/>. + </para> + + <para> + For example, changing the UUID type to <literal>random</literal>: + </para> + +<programlisting> +PUT http://couchdb:5984/_config/uuids/algorithm +Content-Type: application/json +Accept: */* + +"random" +</programlisting> + + <para> + When obtaining a list of UUIDs: + </para> + +<programlisting> +{ + "uuids" : [ + "031aad7b469956cf2826fcb2a9260492", + "6ec875e15e6b385120938df18ee8e496", + "cff9e881516483911aa2f0e98949092d", + "b89d37509d39dd712546f9510d4a9271", + "2e0dbf7f6c4ad716f21938a016e4e59f" + ] +} +</programlisting> + + </section> + + <section id="couchdb-api-misc_favicon_get"> + + <title><literal>GET /favicon.ico</literal></title> + + <para role="meta"> + <remark role="type" condition="urlapi"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="accesstable"/> + + <remark role="itemid" condition="favicon"/> + + <remark role="method" condition="GET"/> + + <remark role="version" condition="inherit"/> + </para> + + <para> + Returns the site icon. The return <literal>Content-type</literal> + header is <literal>image/x-icon</literal>, and the content stream + is the image data. + </para> + + </section> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/couchdb-changes-metasrc.xml b/share/docs/couchdb-manual-1.1/couchdb-changes-metasrc.xml new file mode 100644 index 000000000..338748600 --- /dev/null +++ b/share/docs/couchdb-manual-1.1/couchdb-changes-metasrc.xml @@ -0,0 +1,67 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-single-changes"> + + <title>Changes Feed</title> + + <para> + + </para> + + <para role="meta" id="table-couchdb-single-changes-json-changes"> + <remark role="type" condition="json"/> + + <remark role="src" condition="json"/> + + <remark role="output" condition="itemtable"/> + + <remark role="itemid" condition="changes"/> + + <remark role="version" condition="inherit"/> + </para> + + <section id="couchdb-single-changes-poll"> + + <title>Polling</title> + + <para> + + </para> + + </section> + + <section id="couchdb-single-changes-longpoll"> + + <title>Long Polling</title> + + <para> + + </para> + + </section> + + <section id="couchdb-single-changes-continuous"> + + <title>Continuous</title> + + <para> + + </para> + + </section> + + <section id="couchdb-single-changes-filters"> + + <title>Filters</title> + + <para> + + </para> + + </section> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/couchdb-config-options-metasrc.xml b/share/docs/couchdb-manual-1.1/couchdb-config-options-metasrc.xml new file mode 100644 index 000000000..d8a5fa538 --- /dev/null +++ b/share/docs/couchdb-manual-1.1/couchdb-config-options-metasrc.xml @@ -0,0 +1,393 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE section PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<section id="couchdb-single-config-options"> + + <title>CouchDB Configuration Options</title> + + <para> + + </para> + + <para role="meta" id="table-couchdb-single-config-options-summary"> + <remark role="title">Configuration Groups</remark> + + <remark role="type" condition="config"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="classsummarytable"/> + + <remark role="version" condition="1.0"/> + +<!-- <remark role="idprefix" condition="config-couchdb-options"/>--> + </para> + + <section id="couchdb-single-config-options_attachments"> + + <title><literal>attachments</literal> Configuration Options</title> + + <para> + + </para> + + <para role="meta" id="table-couchdb-single-config-options-attachments-summary"> + <remark role="title">Configuration Groups</remark> + + <remark role="type" condition="config"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="optionsummarytable"/> + + <remark role="version" condition="1.0"/> + + <remark role="itemid" condition="attachments"/> + +<!-- <remark role="idprefix" condition="couchdb-single-config-options_attachments"/> --> + </para> + + </section> + + <section id="couchdb-single-config-options_couchdb"> + + <title><literal>couchdb</literal> Configuration Options</title> + + <para> + + </para> + + <para role="meta" id="table-couchdb-single-config-options-couchdb-summary"> + <remark role="title">Configuration Groups</remark> + + <remark role="type" condition="config"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="optionsummarytable"/> + + <remark role="version" condition="1.0"/> + + <remark role="itemid" condition="couchdb"/> + +<!-- <remark role="idprefix" condition="couchdb-single-config-options_couchdb"/> --> + </para> + + </section> + + <section id="couchdb-single-config-options_daemons"> + + <title><literal>daemons</literal> Configuration Options</title> + + <para> + + </para> + + <para role="meta" id="table-couchdb-single-config-options-daemons-summary"> + <remark role="title">Configuration Groups</remark> + + <remark role="type" condition="config"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="optionsummarytable"/> + + <remark role="version" condition="1.0"/> + + <remark role="itemid" condition="daemons"/> + +<!-- <remark role="idprefix" condition="couchdb-single-config-options_daemons"/> --> + </para> + + </section> + + <section id="couchdb-single-config-options_httpd_db_handlers"> + + <title><literal>httpd_db_handlers</literal> Configuration Options</title> + + <para> + + </para> + + <para role="meta" id="table-couchdb-single-config-options-httpd_db_handlers-summary"> + <remark role="title">Configuration Groups</remark> + + <remark role="type" condition="config"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="optionsummarytable"/> + + <remark role="version" condition="1.0"/> + + <remark role="itemid" condition="httpd_db_handlers"/> + +<!-- <remark role="idprefix" condition="couchdb-single-config-options_httpd_db_handlers"/> --> + </para> + + </section> + + <section id="couchdb-single-config-options_couch_httpd_auth"> + + <title><literal>couch_httpd_auth</literal> Configuration Options</title> + + <para> + + </para> + + <para role="meta" id="table-couchdb-single-config-options-couch_httpd_auth-summary"> + <remark role="title">Configuration Groups</remark> + + <remark role="type" condition="config"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="optionsummarytable"/> + + <remark role="version" condition="1.0"/> + + <remark role="itemid" condition="couch_httpd_auth"/> + +<!-- <remark role="idprefix" condition="couchdb-single-config-options_couch_httpd_auth"/> --> + </para> + + </section> + + <section id="couchdb-single-config-options_httpd"> + + <title><literal>httpd</literal> Configuration Options</title> + + <para> + + </para> + + <para role="meta" id="table-couchdb-single-config-options-httpd-summary"> + <remark role="title">Configuration Groups</remark> + + <remark role="type" condition="config"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="optionsummarytable"/> + + <remark role="version" condition="1.0"/> + + <remark role="itemid" condition="httpd"/> + +<!-- <remark role="idprefix" condition="couchdb-single-config-options_httpd"/> --> + </para> + + </section> + + <section id="couchdb-single-config-options_httpd_design_handlers"> + + <title><literal>httpd_design_handlers</literal> Configuration Options</title> + + <para> + + </para> + + <para role="meta" id="table-couchdb-single-config-options-httpd_design_handlers-summary"> + <remark role="title">Configuration Groups</remark> + + <remark role="type" condition="config"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="optionsummarytable"/> + + <remark role="version" condition="1.0"/> + + <remark role="itemid" condition="httpd_design_handlers"/> + +<!-- <remark role="idprefix" condition="couchdb-single-config-options_httpd_design_handlers"/> --> + </para> + + </section> + + <section id="couchdb-single-config-options_httpd_global_handlers"> + + <title><literal>httpd_global_handlers</literal> Configuration Options</title> + + <para> + + </para> + + <para role="meta" id="table-couchdb-single-config-options-httpd_global_handlers-summary"> + <remark role="title">Configuration Groups</remark> + + <remark role="type" condition="config"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="optionsummarytable"/> + + <remark role="version" condition="1.0"/> + + <remark role="itemid" condition="httpd_global_handlers"/> + +<!-- <remark role="idprefix" condition="couchdb-single-config-options_httpd_global_handlers"/> --> + </para> + + </section> + + <section id="couchdb-single-config-options_log"> + + <title><literal>log</literal> Configuration Options</title> + + <para> + + </para> + + <para role="meta" id="table-couchdb-single-config-options-log-summary"> + <remark role="title">Configuration Groups</remark> + + <remark role="type" condition="config"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="optionsummarytable"/> + + <remark role="version" condition="1.0"/> + + <remark role="itemid" condition="log"/> + +<!-- <remark role="idprefix" condition="couchdb-single-config-options_log"/> --> + </para> + + </section> + + <section id="couchdb-single-config-options_query_servers"> + + <title><literal>query_servers</literal> Configuration Options</title> + + <para> + + </para> + + <para role="meta" id="table-couchdb-single-config-options-query_servers-summary"> + <remark role="title">Configuration Groups</remark> + + <remark role="type" condition="config"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="optionsummarytable"/> + + <remark role="version" condition="1.0"/> + + <remark role="itemid" condition="query_servers"/> + +<!-- <remark role="idprefix" condition="couchdb-single-config-options_query_servers"/> --> + </para> + + </section> + + <section id="couchdb-single-config-options_query_server_config"> + + <title><literal>query_server_config</literal> Configuration Options</title> + + <para> + + </para> + + <para role="meta" id="table-couchdb-single-config-options-query_server_config-summary"> + <remark role="title">Configuration Groups</remark> + + <remark role="type" condition="config"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="optionsummarytable"/> + + <remark role="version" condition="1.0"/> + + <remark role="itemid" condition="query_server_config"/> + +<!-- <remark role="idprefix" condition="couchdb-single-config-options_query_server_config"/> --> + </para> + + </section> + + <section id="couchdb-single-config-options_replicator"> + + <title><literal>replicator</literal> Configuration Options</title> + + <para> + + </para> + + <para role="meta" id="table-couchdb-single-config-options-replicator-summary"> + <remark role="title">Configuration Groups</remark> + + <remark role="type" condition="config"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="optionsummarytable"/> + + <remark role="version" condition="1.0"/> + + <remark role="itemid" condition="replicator"/> + +<!-- <remark role="idprefix" condition="couchdb-single-config-options_replicator"/> --> + </para> + + </section> + + <section id="couchdb-single-config-options_stats"> + + <title><literal>stats</literal> Configuration Options</title> + + <para> + + </para> + + <para role="meta" id="table-couchdb-single-config-options-stats-summary"> + <remark role="title">Configuration Groups</remark> + + <remark role="type" condition="config"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="optionsummarytable"/> + + <remark role="version" condition="1.0"/> + + <remark role="itemid" condition="stats"/> + +<!-- <remark role="idprefix" condition="couchdb-single-config-options_stats"/> --> + </para> + + </section> + + <section id="couchdb-single-config-options_uuids"> + + <title><literal>uuids</literal> Configuration Options</title> + + <para> + + </para> + + <para role="meta" id="table-couchdb-single-config-options-uuids-summary"> + <remark role="title">Configuration Groups</remark> + + <remark role="type" condition="config"/> + + <remark role="src" condition="couchdb"/> + + <remark role="output" condition="optionsummarytable"/> + + <remark role="version" condition="1.0"/> + + <remark role="itemid" condition="uuids"/> + +<!-- <remark role="idprefix" condition="couchdb-single-config-options_uuids"/> --> + </para> + + </section> + +</section> diff --git a/share/docs/couchdb-manual-1.1/couchdb-configuration.xml b/share/docs/couchdb-manual-1.1/couchdb-configuration.xml new file mode 100644 index 000000000..ef1fd2b3c --- /dev/null +++ b/share/docs/couchdb-manual-1.1/couchdb-configuration.xml @@ -0,0 +1,328 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd'> +<chapter id="couchdb-single-configuration"> + + <title>Configuring CouchDB</title> + + <para> + + </para> + + <section id="couchdb-single-configuration-files"> + + <title>CouchDB Configuration Files</title> + + <para> + + </para> + + </section> + + <section id="couchdb-single-configuration-files-locations"> + + <title>Configuration File Locations</title> + + <para> + CouchDB reads files from the following locations, in the following + order. + </para> + + <orderedlist> + + <listitem> + <para> + <filename>PREFIX/default.ini</filename> + </para> + </listitem> + + <listitem> + <para> + <filename>PREFIX/default.d/*</filename> + </para> + </listitem> + + <listitem> + <para> + <filename>PREFIX/local.ini</filename> + </para> + </listitem> + + <listitem> + <para> + <filename>PREFIX/local.d/*</filename> + </para> + </listitem> + + </orderedlist> + + <para> + Settings in successive documents override the settings in earlier + entries. For example, setting the <literal>bind_address</literal> + parameter in <filename>local.ini</filename> would override any + setting in <literal>default.ini</literal>. + </para> + + <warning> + <para> + The <filename>default.ini</filename> file may be overwritten + during an upgrade or re-installation, so localised changes + should be made to the <filename>local.ini</filename> file or + files within the <filename>local.d</filename> directory. + </para> + </warning> + + </section> + + <section id="couchdb-single-configuration-mochiweb"> + + <title>MochiWeb Server Options</title> + + <para> + Server options for the MochiWeb component of CouchDB can be added + to the configuration files. Settings should be added to the + <literal>server_options</literal> option of the + <literal>[httpd]</literal> section of + <filename>local.ini</filename>. For example: + </para> + +<programlisting> +[httpd] +server_options = [{backlog, 128}, {acceptor_pool_size, 16}] + </programlisting> + + </section> + + <section id="couchdb-single-configuration-osprocess"> + + <title>OS Daemons</title> + + <para> + CouchDB now supports starting external processes. The support is + simple and enables CouchDB to start each configured OS daemon. If + the daemon stops at any point, CouchDB will restart it (with + protection to ensure regularly failing daemons are not repeatedly + restarted). + </para> + + <para> + The daemon starting process is one-to-one; for each each + configured daemon in the configuration file, CouchDB will start + exactly one instance. If you need to run multiple instances, then + you must create separate individual configurations. Daemons are + configured within the <literal>[os_daemons]</literal> section of + your configuration file (<filename>local.ini</filename>). The + format of each configured daemon is: + </para> + +<programlisting> +NAME = PATH ARGS + </programlisting> + + <para> + Where <literal>NAME</literal> is an arbitrary (and unique) name to + identify the daemon; <literal>PATH</literal> is the full path to + the daemon to be executed; <literal>ARGS</literal> are any + required arguments to the daemon. + </para> + + <para> + For example: + </para> + +<programlisting> +[os_daemons] +basic_responder = /usr/local/bin/responsder.js +</programlisting> + + <para> + There is no interactivity between CouchDB and the running process, + but you can use the OS Daemons service to create new HTTP servers + and responders and then use the new proxy service to redirect + requests and output to the CouchDB managed service. For more + information on proxying, see + <xref + linkend="couchdb-single-features-proxying"/>. For + further background on the OS Daemon service, see + <ulink url="http://davispj.com/2010/09/26/new-couchdb-externals-api.html">CouchDB + Externals API</ulink> + </para> + + </section> + + <section id="couchdb-single-configuration-update_notification"> + + <title>Update Notifications</title> + + <para> + + </para> + + </section> + + <section id="couchdb-single-configuration-socketoptions"> + + <title>Socket Options Configuration Setting</title> + + <para> + The socket options for the listening socket in CouchDB can now be + set within the CouchDB configuration file. The setting should be + added to the <literal>[httpd]</literal> section of the file using + the option name <literal>socket_options</literal>. The + specification is as a list of tuples. For example: + </para> + +<programlisting> +[httpd] +socket_options = [{recbuf, 262144}, {sndbuf, 262144}, {nodelay, true}] +</programlisting> + + <para> + The options supported are a subset of full options supported by + the TCP/IP stack. A list of the supported options are provided in + the + <ulink + url="http://www.erlang.org/doc/man/inet.html#setopts-2">Erlang + inet</ulink> documentation. + </para> + + </section> + + <section id="couchdb-single-configuration-vhost"> + + <title><literal>vhosts</literal> definitions</title> + + <para> + Similar to the rewrites section of a <literal>_design</literal> + document, the <literal>vhosts</literal> system uses variables in + the form of :varname or wildcards in the form of asterisks. The + variable results can be output into the resulting path as they are + in the rewriter. + </para> + + </section> + + <section id="couchdb-single-configuration-ssl"> + + <title>Configuring SSL Network Sockets</title> + + <para> + SSL configuration in CouchDB was designed to be as easy as + possible. All you need is two files; a certificate and a private + key. If you bought an official SSL certificate from a certificate + authority, both should be in your possession already. + </para> + + <para> + If you just want to try this out and don't want to pay anything + upfront, you can create a self-signed certificate. Everything will + work the same, but clients will get a warning about an insecure + certificate. + </para> + + <para> + You will need the OpenSSL command line tool installed. It probably + already is. + </para> + +<programlisting> +shell> <userinput>mkdir cert && cd cert</userinput> +shell> <userinput>openssl genrsa > privkey.pem</userinput> +shell> <userinput>openssl req -new -x509 -key privkey.pem -out mycert.pem -days 1095</userinput> +shell> <userinput>ls</userinput> +mycert.pem privkey.pem +</programlisting> + + <para> + Now, you need to edit CouchDB's configuration, either by editing + your <filename>local.ini</filename> file or using the + <literal>/_config</literal> API calls or the configuration screen + in Futon. Here is what you need to do in + <filename>local.ini</filename>, you can infer what needs doing in + the other places. + </para> + + <para> + Be sure to make these edits. Under <literal>[daemons]</literal> + you should see: + </para> + +<programlisting> +; enable SSL support by uncommenting the following line and supply the PEM's below. +; the default ssl port CouchDB listens on is 6984 +;httpsd = {couch_httpd, start_link, [https]} +</programlisting> + + <para> + Here uncomment the last line: + </para> + +<programlisting> +httpsd = {couch_httpd, start_link, [https]} +</programlisting> + + <para> + Next, under <literal>[ssl]</literal> you will see: + </para> + +<programlisting> +;cert_file = /full/path/to/server_cert.pem +;key_file = /full/path/to/server_key.pem +</programlisting> + + <para> + Uncomment and adjust the paths so it matches your system's paths: + </para> + +<programlisting> +cert_file = /home/jan/cert/mycert.pem +key_file = /home/jan/cert/privkey.pem +</programlisting> + + <para> + For more information please read + <ulink + url="http://www.openssl.org/docs/HOWTO/certificates.txt">http://www.openssl.org/docs/HOWTO/certificates.txt</ulink>. + </para> + + <para> + Now start (or restart) CouchDB. You should be able to connect to + it using HTTPS on port 6984: + </para> + +<programlisting> +shell> <userinput>curl https://127.0.0.1:6984/</userinput> +curl: (60) SSL certificate problem, verify that the CA cert is OK. Details: +error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed +More details here: http://curl.haxx.se/docs/sslcerts.html + +curl performs SSL certificate verification by default, using a "bundle" +of Certificate Authority (CA) public keys (CA certs). If the default +bundle file isn't adequate, you can specify an alternate file +using the --cacert option. +If this HTTPS server uses a certificate signed by a CA represented in +the bundle, the certificate verification probably failed due to a +problem with the certificate (it might be expired, or the name might +not match the domain name in the URL). +If you'd like to turn off curl's verification of the certificate, use +the -k (or --insecure) option. +</programlisting> + + <para> + Oh no what happened?! — Remember, clients will notify their + users that your certificate is self signed. + <command>curl</command> is the client in this case and it notifies + you. Luckily you trust yourself (don't you?) and you can specify + the <option>-k</option> option as the message reads: + </para> + +<programlisting> +shell> <userinput>curl -k https://127.0.0.1:6984/</userinput> +{"couchdb":"Welcome","version":"1.1.0"} +</programlisting> + + </section> + + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="metadoc-couchdb-config-options.xml"/> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/couchdb-dbmaint.xml b/share/docs/couchdb-manual-1.1/couchdb-dbmaint.xml new file mode 100644 index 000000000..bdd4184a0 --- /dev/null +++ b/share/docs/couchdb-manual-1.1/couchdb-dbmaint.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-single-dbmaint"> + + <title>Database Maintenance</title> + + <para> + + </para> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/couchdb-features.xml b/share/docs/couchdb-manual-1.1/couchdb-features.xml new file mode 100644 index 000000000..3c7edc39f --- /dev/null +++ b/share/docs/couchdb-manual-1.1/couchdb-features.xml @@ -0,0 +1,301 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-single-features"> + + <title>Features and Functionality</title> + + <para> + + </para> + + <section id="couchdb-single-features-httprange"> + + <title>HTTP Range Requests</title> + + <para> + HTTP allows you to specify byte ranges for requests. This allows + the implementation of resumable downloads and skippable audio and + video streams alike. The following example uses a text file to + make the range request process easier. + </para> + +<programlisting> +shell> <userinput>cat file.txt</userinput> +My hovercraft is full of eels! +</programlisting> + + <para> + Uploading this as an attachment to a <literal>text</literal> + database using <command>curl</command>: + </para> + +<programlisting> +shell> <userinput>curl -X PUT http://127.0.0.1:5984/test/doc/file.txt \ + -H "Content-Type: application/octet-stream" -d@file.txt</userinput> +{"ok":true,"id":"doc","rev":"1-287a28fa680ae0c7fb4729bf0c6e0cf2"} +</programlisting> + + <para> + Requesting the whole file works as normal: + </para> + +<programlisting> +shell> <userinput>curl -X GET http://127.0.0.1:5984/test/doc/file.txt</userinput> +My hovercraft is full of eels! +</programlisting> + + <para> + But to retrieve only the first 13 bytes using + <command>curl</command>: + </para> + +<programlisting> +shell> <userinput>curl -X GET http://127.0.0.1:5984/test/doc/file.txt -H "Range: bytes=0-12"</userinput> +My hovercraft +</programlisting> + + <para> + HTTP supports many ways to specify single and even multiple byte + rangers. See + <ulink + url="http://tools.ietf.org/html/rfc2616#section-14.27">RFC + 2616</ulink>. + </para> + + <note> + <para> + Databases that have been created with CouchDB 1.0.2 or earlier + will support range requests in 1.1.0, but they are using a + less-optimal algorithm. If you plan to make heavy use of this + feature, make sure to compact your database with CouchDB 1.1.0 + to take advantage of a better algorithm to find byte ranges. + </para> + </note> + + </section> + + <section id="couchdb-single-features-proxying"> + + <title>HTTP Proxying</title> + + <para> + The HTTP proxy feature makes it easy to map and redirect different + content through your CouchDB URL. The proxy works by mapping a + pathname and passing all content after that prefix through to the + configured proxy address. + </para> + + <para> + Configuration of the proxy redirect is handled through the + <literal>[httpd_global_handlers]</literal> section of the CouchDB + configuration file (typically <filename>local.ini</filename>). The + format is: + </para> + +<programlisting> +[httpd_global_handlers] +PREFIX = {couch_httpd_proxy, handle_proxy_req, <<"DESTINATION">>} + </programlisting> + + <para> + Where: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal>PREFIX</literal> + </para> + + <para> + Is the string that will be matched. The string can be any + valid qualifier, although to ensure that existing database + names are not overridden by a proxy configuration, you can use + an underscore prefix. + </para> + </listitem> + + <listitem> + <para> + <literal>DESTINATION</literal> + </para> + + <para> + The fully-qualified URL to which the request should be sent. + The destination must include the <literal>http</literal> + prefix. The content is used verbatim in the original request, + so you can also forward to servers on different ports and to + specific paths on the target host. + </para> + </listitem> + + </itemizedlist> + + <para> + The proxy process then translates requests of the form: + </para> + +<programlisting> +http://couchdb:5984/PREFIX/path +</programlisting> + + <para> + To: + </para> + +<programlisting> +DESTINATION/path +</programlisting> + + <note> + <para> + Everything after <literal>PREFIX</literal> including the + required forward slash will be appended to the + <literal>DESTINATION</literal>. + </para> + </note> + + <para> + The response is then communicated back to the original client. + </para> + + <para> + For example, the following configuration: + </para> + +<programlisting> +<![CDATA[ +_google = {couch_httpd_proxy, handle_proxy_req, <<"http://www.google.com">>}]]> +</programlisting> + + <para> + Would forward all requests for + <literal>http://couchdb:5984/_google</literal> to the Google + website. + </para> + + <para> + The service can also be used to forward to related CouchDB + services, such as Lucene: + </para> + +<programlisting> + <![CDATA[ +[httpd_global_handlers] +_fti = {couch_httpd_proxy, handle_proxy_req, <<"http://127.0.0.1:5985">>}]]> +</programlisting> + + <note> + <para> + The proxy service is basic. If the request is not identified by + the <literal>DESTINATION</literal>, or the remainder of the + <literal>PATH</literal> specification is incomplete, the + original request URL is interpreted as if the + <literal>PREFIX</literal> component of that URL does not exist. + </para> + + <para> + For example, requesting + <literal>http://couchdb:5984/_intranet/media</literal> when + <filename>/media</filename> on the proxy destination does not + exist, will cause the request URL to be interpreted as + <literal>http://couchdb:5984/media</literal>. Care should be + taken to ensure that both requested URLs and destination URLs + are able to cope + </para> + </note> + + </section> + + <section id="couchdb-single-features-commonjs"> + + <title>CommonJS support for map functions</title> + + <para> + CommonJS support allows you to use CommonJS notation inside + <methodname>map</methodname> and <methodname>reduce</methodname> + functions, but only of libraries that are stored inside the views + part of the design doc. + </para> + + <para> + So you could continue to access CommonJS code in design_doc.foo, + from your list functions etc, but we'd add the ability to require + CommonJS modules within map and reduce, but only from + <filename>design_doc.views.lib</filename>. + </para> + + <para> + There's no worry here about namespace collisions, as Couch just + plucks <literal>views.*.map</literal> and + <literal>views.*.reduce</literal> out of the design doc. So you + could have a view called <literal>lib</literal> if you wanted, and + still have CommonJS stored in <literal>views.lib.sha1</literal> + and <literal>views.lib.stemmer</literal> if you wanted. + </para> + + <para> + The implementation is simplified by enforcing that CommonJS + modules to be used in <methodname>map</methodname> functions be + stored in views.lib. + </para> + + <para> + A sample design doc (taken from the test suite in Futon) is below: + </para> + +<programlisting> +{ + "views" : { + "lib" : { + "baz" : "exports.baz = 'bam';", + "foo" : { + "zoom" : "exports.zoom = 'yeah';", + "boom" : "exports.boom = 'ok';", + "foo" : "exports.foo = 'bar';" + } + }, + "commonjs" : { + "map" : "function(doc) { emit(null, require('views/lib/foo/boom').boom)}" + } + }, + "_id" : "_design/test" +} +</programlisting> + + <para> + The <literal>require()</literal> statement is relative to the + design document, but anything loaded form outside of + <literal>views/lib</literal> will fail. + </para> + + </section> + + <section id="couchdb-single-features-etag"> + + <title>Granular ETag support</title> + + <para> + ETags have been assigned to a map/reduce group (the collection of + views in a single design document). Any change to any of the + indexes for those views would generate a new ETag for all view + URL's in a single design doc, even if that specific view's results + had not changed. + </para> + + <para> + In CouchDB 1.1 each <literal>_view</literal> URL has it's own ETag + which only gets updated when changes are made to the database that + effect that index. If the index for that specific view does not + change, that view keeps the original ETag head (therefore sending + back 304 Not Modified more often). + </para> + + </section> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/couchdb-introduction.xml b/share/docs/couchdb-manual-1.1/couchdb-introduction.xml new file mode 100644 index 000000000..15c123bc9 --- /dev/null +++ b/share/docs/couchdb-manual-1.1/couchdb-introduction.xml @@ -0,0 +1,578 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-single-introduction"> + + <title>Introduction</title> + + <para> + There are two interfaces to CouchDB, the built-in + Futon web-based interface and the CouchDB API accessed through the + HTTP REST interface. The former is the simplest way to view and + monitor your CouchDB installation and perform a + number of basic database and system operations. More information on + using the Futon interface can be found in + <xref linkend="couchdb-single-introduction-futon"/>. + </para> + + <para> + The primary way to interact with the CouchDB API is to use a client + library or other interface that provides access to the underlying + functionality through your chosen language or platform. However, + since the API is supported through HTTP REST, you can interact with + your CouchDB with any solution that supports the + HTTP protocol. + </para> + + <para> + There are a number of different tools that talk the HTTP protocol + and allow you to set and configure the necessary information. One + tool for this that allows for access from the command-line is + <command>curl</command>. See + <xref + linkend="couchdb-single-introduction-curl"/>. + </para> + + <section id="couchdb-single-introduction-futon"> + + <title>Using Futon</title> + + <para> + Futon is a native web-based interface built into CouchDB. It provides a basic interface to the majority of the + functionality, including the ability to create, update, delete and + view documents and views, provides access to the configuration + parameters, and an interface for initiating replication. + </para> + + <para> + The default view is the <guilabel>Overview</guilabel> page which + provides you with a list of the databases. The basic structure of + the page is consistent regardless of the section you are in. The + main panel on the left provides the main interface to the + databases, configuration or replication systems. The side panel on + the right provides navigation to the main areas of Futon + interface: + </para> + + <figure id="fig-ccouchdb-single-introduction-futon-overview"> + + <title>Futon Overview</title> + + <mediaobject> + + <imageobject> + + <imagedata width="100%" contentdepth="100%" scalefit="1" +fileref="images/futon-overview.png" +format="PNG" lang="en"/> + + </imageobject> + + <textobject> + + <phrase lang="en">Futon Overview</phrase> + + </textobject> + + </mediaobject> + + </figure> + + <para> + The main sections are: + </para> + + <itemizedlist> + + <listitem> + <para> + <guibutton>Overview</guibutton> + </para> + + <para> + The main overview page, which provides a list of the databases + and provides the interface for querying the database and + creating and updating documents. See + <xref + linkend="couchdb-single-introduction-futon-dbdocs"/>. + </para> + </listitem> + + <listitem> + <para> + <guibutton>Configuration</guibutton> + </para> + + <para> + An interface into the configuration of your CouchDB installation. The interface allows you to edit the + different configurable parameters. For more details on + configuration, see + <xref + linkend="couchdb-single-configuration"/>. + </para> + </listitem> + + <listitem> + <para> + <guibutton>Replicator</guibutton> + </para> + + <para> + An interface to the replication system, enabling you to + initiate replication between local and remote databases. See + <xref + linkend="couchdb-single-introduction-futon-replication"/>. + </para> + </listitem> + + <listitem> + <para> + <guibutton>Status</guibutton> + </para> + + <para> + Displays a list of the running background tasks on the server. + Background tasks include view index building, compaction and + replication. The <guibutton>Status</guibutton> page is an + interface to the + <link linkend="couchdb-api-misc_active-tasks_get">Active + Tasks</link> API call. See + <xref + linkend="couchdb-api-misc_active-tasks_get"/>. + </para> + </listitem> + + <listitem> + <para> + <guibutton>Verify Installation</guibutton> + </para> + + <para> + The <guibutton>Verify Installation</guibutton> allows you to + check whether all of the components of your CouchDB installation are correctly installed. + </para> + </listitem> + + <listitem> + <para> + <guibutton>Test Suite</guibutton> + </para> + + <para> + The <guibutton>Test Suite</guibutton> section allows you to + run the built-in test suite. This executes a number of test + routines entirely within your browser to test the API and + functionality of your CouchDB installation. If + you select this page, you can run the tests by using the + <guibutton>Run All</guibutton> button. This will execute all + the tests, which may take some time. + </para> + </listitem> + + </itemizedlist> + + <section id="couchdb-single-introduction-futon-dbdocs"> + + <title>Managing Databases and Documents</title> + + <para> + You can manage databases and documents within Futon using the + main <guibutton>Overview</guibutton> section of the Futon + interface. + </para> + + <para> + To create a new database, click the <guibutton>Create Database + &ellipsis;</guibutton> button. You will be prompted for the + database name, as shown in the figure below. + </para> + + <figure id="fig-ccouchdb-single-introduction-futon-dbdocs-createdb"> + + <title>Creating a Database</title> + + <mediaobject> + + <imageobject> + + <imagedata width="100%" contentdepth="100%" scalefit="1" +fileref="images/futon-createdb.png" +format="PNG" lang="en"/> + + </imageobject> + + <textobject> + + <phrase lang="en">Creating a Database</phrase> + + </textobject> + + </mediaobject> + + </figure> + + <para> + Once you have created the database (or selected an existing + one), you will be shown a list of the current documents. If you + create a new document, or select an existing document, you will + be presented with the edit document display. + </para> + + <para> + Editing documents within Futon requires selecting the document + and then editing (and setting) the fields for the document + individually before saving the document back into the database. + </para> + + <para> + For example, the figure below shows the editor for a single + document, a newly created document with a single ID, the + document <literal>_id</literal> field. + </para> + + <figure id="fig-ccouchdb-single-introduction-futon-dbdocs-editdoc"> + + <title>Editing a Document</title> + + <mediaobject> + + <imageobject> + + <imagedata width="100%" contentdepth="100%" scalefit="1" +fileref="images/futon-editdoc.png" +format="PNG" lang="en"/> + + </imageobject> + + <textobject> + + <phrase lang="en">Editing a Document</phrase> + + </textobject> + + </mediaobject> + + </figure> + + <para> + To add a field to the document: + </para> + + <orderedlist> + + <listitem> + <para> + Click <guibutton>Add Field</guibutton>. + </para> + </listitem> + + <listitem> + <para> + In the fieldname box, enter the name of the field you want + to create. For example, <quote>company</quote>. + </para> + </listitem> + + <listitem> + <para> + Click the green tick next to the field name to confirm the + field name change. + </para> + </listitem> + + <listitem> + <para> + Double-click the corresponding <guilabel>Value</guilabel> + cell. + </para> + </listitem> + + <listitem> + <para> + Enter a company name, for example <quote>Example</quote>. + </para> + </listitem> + + <listitem> + <para> + Click the green tick next to the field value to confirm the + field value. + </para> + </listitem> + + <listitem> + <para> + The document is still not saved as this point. You must + explicitly save the document by clicking the <guibutton>Save + Document</guibutton> button at the top of the page. This + will save the document, and then display the new document + with the saved revision information (the + <literal>_rev</literal> field). + </para> + + <figure + id="fig-ccouchdb-single-introduction-futon-dbdocs-finaldoc"> + + <title>Edited Document</title> + + <mediaobject> + + <imageobject> + + <imagedata width="100%" contentdepth="100%" scalefit="1" +fileref="images/futon-editeddoc.png" +format="PNG" lang="en"/> + + </imageobject> + + <textobject> + + <phrase lang="en">Edited Document</phrase> + + </textobject> + + </mediaobject> + + </figure> + </listitem> + + </orderedlist> + + <para> + The same basic interface is used for all editng operations + within Futon. You <emphasis>must</emphasis> rememmbr to save the + individual element (fieldname, value) using the green tick + button, before then saving the document. + </para> + + </section> + + <section id="couchdb-single-introduction-futon-replication"> + + <title>Configuring Replication</title> + + <para> + When you click the <guibutton>Replicator</guibutton> option + within the <guilabel>Tools</guilabel> menu you are presented + with the Replicator screen. This allows you to start replication + between two databases by filling in or select the appropriate + options within the form provided. + </para> + + <figure + id="fig-ccouchdb-single-introduction-futon-replication-form"> + + <title>Replication Form</title> + + <mediaobject> + + <imageobject> + + <imagedata width="100%" contentdepth="100%" scalefit="1" +fileref="images/futon-replform.png" +format="PNG" lang="en"/> + + </imageobject> + + <textobject> + + <phrase lang="en">Replication Form</phrase> + + </textobject> + + </mediaobject> + + </figure> + + <para> + To start a replication process, either the select the local + database or enter a remote database name into the corresponding + areas of the form. Replication occurs from the database on the + left to the database on the right. + </para> + + <para> + If you are specifying a remote database name, you must specify + the full URL of the remote database (including the host, port + number and database name). If the remote instance requires + authentication, you can specify the username and password as + part of the URL, for example + <literal>http://username:pass@remotehost:5984/demo</literal>. + </para> + + <para> + To enable continuous replication, click the + <guilabel>Continuous</guilabel> checkbox. + </para> + + <para> + To start the replication process, click the + <guibutton>Replicate</guibutton> button. The replication process + should start and will continue in the background. If the + replication process will take a long time, you can monitor the + status of the replication using the + <guibutton>Status</guibutton> option under the + <guilabel>Tools</guilabel> menu. + </para> + + <para> + Once replication has been completed, the page will show the + information returned when the replication process completes by + the API. + </para> + + <para> + The <guilabel>Replicator</guilabel> tool is an interface to the + underlying replication API. For more information, see + <xref + linkend="couchdb-api-misc_replicate_post"/>. + For more information on replication, see + <xref linkend="couchdb-single-replication"/>. + </para> + + </section> + + </section> + + <section id="couchdb-single-introduction-curl"> + + <title>Using <command>curl</command></title> + + <para> + The <command>curl</command> utility is a command line tool + available on Unix, Linux, Mac OS X and Windows and many other + platforms. <command>curl</command> provides easy access to the + HTTP protocol (among others) directly from the command-line and is + therefore an ideal way of interacting with CouchDB + over the HTTP REST API. + </para> + + <para> + For simple <literal>GET</literal> requests you can supply the URL + of the request. For example, to get the database information: + </para> + +<programlisting> +shell> <userinput>curl http://127.0.0.1:5984</userinput> +</programlisting> + + <para> + This returns the database information (formatted in the output + below for clarity): + </para> + +<programlisting> +{ + "modules" : { + "geocouch" : "7fd793c10f3aa667a1088a937398bc5b51472b7f" + }, + "couchdb" : "Welcome", + "version" : "1.1.0", +} +</programlisting> + + <note> + <para> + For some URLs, especially those that include special characters + such as ampersand, exclamation mark, or question mark, you + should quote the URL you are specifying on the command line. For + example: + </para> + +<programlisting> +shell> <userinput>curl 'http://couchdb:5984/_uuids?count=5'</userinput> +</programlisting> + </note> + + <para> + You can explicitly set the HTTP command using the + <option>-X</option> command line option. For example, when + creating a database, you set the name of the database in the URL + you send using a PUT request: + </para> + +<programlisting> +shell> <userinput>curl -X PUT http://127.0.0.1:5984/demo</userinput> +{"ok":true} +</programlisting> + + <para> + But to obtain the database information you use a + <literal>GET</literal> request (with the return information + formatted for clarity): + </para> + +<programlisting> +shell> <userinput>curl -X GET http://127.0.0.1:5984/demo</userinput> +{ + "compact_running" : false, + "doc_count" : 0, + "db_name" : "demo", + "purge_seq" : 0, + "committed_update_seq" : 0, + "doc_del_count" : 0, + "disk_format_version" : 5, + "update_seq" : 0, + "instance_start_time" : "1306421773496000", + "disk_size" : 79 +} +</programlisting> + + <para> + For certain operations, you must specify the content type of + request, which you do by specifying the + <literal>Content-Type</literal> header using the + <option>-H</option> command-line option: + </para> + +<programlisting> +shell> <userinput>curl -H 'Content-type: application/json' http://127.0.0.1:5984/_uuids</userinput> +</programlisting> + + <para> + You can also submit 'payload' data, that is, data in the body of + the HTTP request using the <option>-d</option> option. This is + useful if you need to submit JSON structures, for example document + data, as part of the request. For example, to submit a simple + document to the <literal>demo</literal> database: + </para> + +<programlisting> +shell> <userinput>curl -H 'Content-type: application/json' \ + -X POST http://127.0.0.1:5984/demo \ + -d '{"company": "Example, Inc."}'</userinput> +{"ok":true,"id":"8843faaf0b831d364278331bc3001bd8", + "rev":"1-33b9fbce46930280dab37d672bbc8bb9"} +</programlisting> + + <para> + In the above example, the argument after the <option>-d</option> + option is the JSON of the document we want to submit. + </para> + + <para> + The document can be accessed by using the automatically generated + document ID that was returned: + </para> + +<programlisting> +shell> <userinput>curl -X GET http://127.0.0.1:5984/demo/8843faaf0b831d364278331bc3001bd8</userinput> +{"_id":"8843faaf0b831d364278331bc3001bd8", + "_rev":"1-33b9fbce46930280dab37d672bbc8bb9", + "company":"Example, Inc."} +</programlisting> + + <para> + The API samples in the <xref linkend="couchdb-api-basics"/> show + the HTTP command, URL and any payload information that needs to be + submitted (and the expected return value). All of these examples + can be reproduced using <command>curl</command> with the + command-line examples shown above. + </para> + + </section> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/couchdb-manual-ready.xml b/share/docs/couchdb-manual-1.1/couchdb-manual-ready.xml new file mode 100644 index 000000000..8667927bd --- /dev/null +++ b/share/docs/couchdb-manual-1.1/couchdb-manual-ready.xml @@ -0,0 +1,9409 @@ +<?xml version="1.0" encoding="utf-8" standalone="no"?> +<book id="couchdb-1-1"> + + <title>CouchDB 1.1 Manual</title> + + <bookinfo> + + <abstract> + + <para> + This manual documents the CouchDB + 1.1 database system, including the installation, + functionality, and CouchDB API. + </para> + + <para xml:base="../common/docbuilddate.xml"> + <emphasis>Last document update</emphasis>: 21 Feb 2012 20:09; + <emphasis>Document built</emphasis>: 21 Feb 2012 20:9. +</para> + + </abstract> + + </bookinfo> + + <chapter id="couchdb-single-introduction"> + + <title>Introduction</title> + + <para> + There are two interfaces to CouchDB, the built-in + Futon web-based interface and the CouchDB API accessed through the + HTTP REST interface. The former is the simplest way to view and + monitor your CouchDB installation and perform a + number of basic database and system operations. More information on + using the Futon interface can be found in + <xref linkend="couchdb-single-introduction-futon"/>. + </para> + + <para> + The primary way to interact with the CouchDB API is to use a client + library or other interface that provides access to the underlying + functionality through your chosen language or platform. However, + since the API is supported through HTTP REST, you can interact with + your CouchDB with any solution that supports the + HTTP protocol. + </para> + + <para> + There are a number of different tools that talk the HTTP protocol + and allow you to set and configure the necessary information. One + tool for this that allows for access from the command-line is + <command moreinfo="none">curl</command>. See + <xref linkend="couchdb-single-introduction-curl"/>. + </para> + + <section id="couchdb-single-introduction-futon"> + + <title>Using Futon</title> + + <para> + Futon is a native web-based interface built into CouchDB. It provides a basic interface to the majority of the + functionality, including the ability to create, update, delete and + view documents and views, provides access to the configuration + parameters, and an interface for initiating replication. + </para> + + <para> + The default view is the <guilabel moreinfo="none">Overview</guilabel> page which + provides you with a list of the databases. The basic structure of + the page is consistent regardless of the section you are in. The + main panel on the left provides the main interface to the + databases, configuration or replication systems. The side panel on + the right provides navigation to the main areas of Futon + interface: + </para> + + <figure id="fig-ccouchdb-single-introduction-futon-overview" float="0"> + + <title>Futon Overview</title> + + <mediaobject> + + <imageobject> + + <imagedata width="100%" contentdepth="100%" scalefit="1" fileref="images/futon-overview.png" format="PNG" lang="en"/> + + </imageobject> + + <textobject> + + <phrase lang="en">Futon Overview</phrase> + + </textobject> + + </mediaobject> + + </figure> + + <para> + The main sections are: + </para> + + <itemizedlist> + + <listitem> + <para> + <guibutton moreinfo="none">Overview</guibutton> + </para> + + <para> + The main overview page, which provides a list of the databases + and provides the interface for querying the database and + creating and updating documents. See + <xref linkend="couchdb-single-introduction-futon-dbdocs"/>. + </para> + </listitem> + + <listitem> + <para> + <guibutton moreinfo="none">Configuration</guibutton> + </para> + + <para> + An interface into the configuration of your CouchDB installation. The interface allows you to edit the + different configurable parameters. For more details on + configuration, see + <xref linkend="couchdb-single-configuration"/>. + </para> + </listitem> + + <listitem> + <para> + <guibutton moreinfo="none">Replicator</guibutton> + </para> + + <para> + An interface to the replication system, enabling you to + initiate replication between local and remote databases. See + <xref linkend="couchdb-single-introduction-futon-replication"/>. + </para> + </listitem> + + <listitem> + <para> + <guibutton moreinfo="none">Status</guibutton> + </para> + + <para> + Displays a list of the running background tasks on the server. + Background tasks include view index building, compaction and + replication. The <guibutton moreinfo="none">Status</guibutton> page is an + interface to the + <link linkend="couchdb-api-misc_active-tasks_get">Active + Tasks</link> API call. See + <xref linkend="couchdb-api-misc_active-tasks_get"/>. + </para> + </listitem> + + <listitem> + <para> + <guibutton moreinfo="none">Verify Installation</guibutton> + </para> + + <para> + The <guibutton moreinfo="none">Verify Installation</guibutton> allows you to + check whether all of the components of your CouchDB installation are correctly installed. + </para> + </listitem> + + <listitem> + <para> + <guibutton moreinfo="none">Test Suite</guibutton> + </para> + + <para> + The <guibutton moreinfo="none">Test Suite</guibutton> section allows you to + run the built-in test suite. This executes a number of test + routines entirely within your browser to test the API and + functionality of your CouchDB installation. If + you select this page, you can run the tests by using the + <guibutton moreinfo="none">Run All</guibutton> button. This will execute all + the tests, which may take some time. + </para> + </listitem> + + </itemizedlist> + + <section id="couchdb-single-introduction-futon-dbdocs"> + + <title>Managing Databases and Documents</title> + + <para> + You can manage databases and documents within Futon using the + main <guibutton moreinfo="none">Overview</guibutton> section of the Futon + interface. + </para> + + <para> + To create a new database, click the <guibutton moreinfo="none">Create Database + …</guibutton> button. You will be prompted for the + database name, as shown in the figure below. + </para> + + <figure id="fig-ccouchdb-single-introduction-futon-dbdocs-createdb" float="0"> + + <title>Creating a Database</title> + + <mediaobject> + + <imageobject> + + <imagedata width="100%" contentdepth="100%" scalefit="1" fileref="images/futon-createdb.png" format="PNG" lang="en"/> + + </imageobject> + + <textobject> + + <phrase lang="en">Creating a Database</phrase> + + </textobject> + + </mediaobject> + + </figure> + + <para> + Once you have created the database (or selected an existing + one), you will be shown a list of the current documents. If you + create a new document, or select an existing document, you will + be presented with the edit document display. + </para> + + <para> + Editing documents within Futon requires selecting the document + and then editing (and setting) the fields for the document + individually before saving the document back into the database. + </para> + + <para> + For example, the figure below shows the editor for a single + document, a newly created document with a single ID, the + document <literal moreinfo="none">_id</literal> field. + </para> + + <figure id="fig-ccouchdb-single-introduction-futon-dbdocs-editdoc" float="0"> + + <title>Editing a Document</title> + + <mediaobject> + + <imageobject> + + <imagedata width="100%" contentdepth="100%" scalefit="1" fileref="images/futon-editdoc.png" format="PNG" lang="en"/> + + </imageobject> + + <textobject> + + <phrase lang="en">Editing a Document</phrase> + + </textobject> + + </mediaobject> + + </figure> + + <para> + To add a field to the document: + </para> + + <orderedlist inheritnum="ignore" continuation="restarts"> + + <listitem> + <para> + Click <guibutton moreinfo="none">Add Field</guibutton>. + </para> + </listitem> + + <listitem> + <para> + In the fieldname box, enter the name of the field you want + to create. For example, <quote>company</quote>. + </para> + </listitem> + + <listitem> + <para> + Click the green tick next to the field name to confirm the + field name change. + </para> + </listitem> + + <listitem> + <para> + Double-click the corresponding <guilabel moreinfo="none">Value</guilabel> + cell. + </para> + </listitem> + + <listitem> + <para> + Enter a company name, for example <quote>Example</quote>. + </para> + </listitem> + + <listitem> + <para> + Click the green tick next to the field value to confirm the + field value. + </para> + </listitem> + + <listitem> + <para> + The document is still not saved as this point. You must + explicitly save the document by clicking the <guibutton moreinfo="none">Save + Document</guibutton> button at the top of the page. This + will save the document, and then display the new document + with the saved revision information (the + <literal moreinfo="none">_rev</literal> field). + </para> + + <figure id="fig-ccouchdb-single-introduction-futon-dbdocs-finaldoc" float="0"> + + <title>Edited Document</title> + + <mediaobject> + + <imageobject> + + <imagedata width="100%" contentdepth="100%" scalefit="1" fileref="images/futon-editeddoc.png" format="PNG" lang="en"/> + + </imageobject> + + <textobject> + + <phrase lang="en">Edited Document</phrase> + + </textobject> + + </mediaobject> + + </figure> + </listitem> + + </orderedlist> + + <para> + The same basic interface is used for all editng operations + within Futon. You <emphasis>must</emphasis> rememmbr to save the + individual element (fieldname, value) using the green tick + button, before then saving the document. + </para> + + </section> + + <section id="couchdb-single-introduction-futon-replication"> + + <title>Configuring Replication</title> + + <para> + When you click the <guibutton moreinfo="none">Replicator</guibutton> option + within the <guilabel moreinfo="none">Tools</guilabel> menu you are presented + with the Replicator screen. This allows you to start replication + between two databases by filling in or select the appropriate + options within the form provided. + </para> + + <figure id="fig-ccouchdb-single-introduction-futon-replication-form" float="0"> + + <title>Replication Form</title> + + <mediaobject> + + <imageobject> + + <imagedata width="100%" contentdepth="100%" scalefit="1" fileref="images/futon-replform.png" format="PNG" lang="en"/> + + </imageobject> + + <textobject> + + <phrase lang="en">Replication Form</phrase> + + </textobject> + + </mediaobject> + + </figure> + + <para> + To start a replication process, either the select the local + database or enter a remote database name into the corresponding + areas of the form. Replication occurs from the database on the + left to the database on the right. + </para> + + <para> + If you are specifying a remote database name, you must specify + the full URL of the remote database (including the host, port + number and database name). If the remote instance requires + authentication, you can specify the username and password as + part of the URL, for example + <literal moreinfo="none">http://username:pass@remotehost:5984/demo</literal>. + </para> + + <para> + To enable continuous replication, click the + <guilabel moreinfo="none">Continuous</guilabel> checkbox. + </para> + + <para> + To start the replication process, click the + <guibutton moreinfo="none">Replicate</guibutton> button. The replication process + should start and will continue in the background. If the + replication process will take a long time, you can monitor the + status of the replication using the + <guibutton moreinfo="none">Status</guibutton> option under the + <guilabel moreinfo="none">Tools</guilabel> menu. + </para> + + <para> + Once replication has been completed, the page will show the + information returned when the replication process completes by + the API. + </para> + + <para> + The <guilabel moreinfo="none">Replicator</guilabel> tool is an interface to the + underlying replication API. For more information, see + <xref linkend="couchdb-api-misc_replicate_post"/>. + For more information on replication, see + <xref linkend="couchdb-single-replication"/>. + </para> + + </section> + + </section> + + <section id="couchdb-single-introduction-curl"> + + <title>Using <command moreinfo="none">curl</command></title> + + <para> + The <command moreinfo="none">curl</command> utility is a command line tool + available on Unix, Linux, Mac OS X and Windows and many other + platforms. <command moreinfo="none">curl</command> provides easy access to the + HTTP protocol (among others) directly from the command-line and is + therefore an ideal way of interacting with CouchDB + over the HTTP REST API. + </para> + + <para> + For simple <literal moreinfo="none">GET</literal> requests you can supply the URL + of the request. For example, to get the database information: + </para> + +<programlisting format="linespecific">shell> <userinput moreinfo="none">curl http://127.0.0.1:5984</userinput></programlisting> + + <para> + This returns the database information (formatted in the output + below for clarity): + </para> + +<programlisting format="linespecific">{ + "modules" : { + "geocouch" : "7fd793c10f3aa667a1088a937398bc5b51472b7f" + }, + "couchdb" : "Welcome", + "version" : "1.1.0", +}</programlisting> + + <note> + <para> + For some URLs, especially those that include special characters + such as ampersand, exclamation mark, or question mark, you + should quote the URL you are specifying on the command line. For + example: + </para> + +<programlisting format="linespecific">shell> <userinput moreinfo="none">curl 'http://couchdb:5984/_uuids?count=5'</userinput></programlisting> + </note> + + <para> + You can explicitly set the HTTP command using the + <option>-X</option> command line option. For example, when + creating a database, you set the name of the database in the URL + you send using a PUT request: + </para> + +<programlisting format="linespecific">shell> <userinput moreinfo="none">curl -X PUT http://127.0.0.1:5984/demo</userinput> +{"ok":true}</programlisting> + + <para> + But to obtain the database information you use a + <literal moreinfo="none">GET</literal> request (with the return information + formatted for clarity): + </para> + +<programlisting format="linespecific">shell> <userinput moreinfo="none">curl -X GET http://127.0.0.1:5984/demo</userinput> +{ + "compact_running" : false, + "doc_count" : 0, + "db_name" : "demo", + "purge_seq" : 0, + "committed_update_seq" : 0, + "doc_del_count" : 0, + "disk_format_version" : 5, + "update_seq" : 0, + "instance_start_time" : "1306421773496000", + "disk_size" : 79 +}</programlisting> + + <para> + For certain operations, you must specify the content type of + request, which you do by specifying the + <literal moreinfo="none">Content-Type</literal> header using the + <option>-H</option> command-line option: + </para> + +<programlisting format="linespecific">shell> <userinput moreinfo="none">curl -H 'Content-type: application/json' http://127.0.0.1:5984/_uuids</userinput></programlisting> + + <para> + You can also submit 'payload' data, that is, data in the body of + the HTTP request using the <option>-d</option> option. This is + useful if you need to submit JSON structures, for example document + data, as part of the request. For example, to submit a simple + document to the <literal moreinfo="none">demo</literal> database: + </para> + +<programlisting format="linespecific">shell> <userinput moreinfo="none">curl -H 'Content-type: application/json' \ + -X POST http://127.0.0.1:5984/demo \ + -d '{"company": "Example, Inc."}'</userinput> +{"ok":true,"id":"8843faaf0b831d364278331bc3001bd8", + "rev":"1-33b9fbce46930280dab37d672bbc8bb9"}</programlisting> + + <para> + In the above example, the argument after the <option>-d</option> + option is the JSON of the document we want to submit. + </para> + + <para> + The document can be accessed by using the automatically generated + document ID that was returned: + </para> + +<programlisting format="linespecific">shell> <userinput moreinfo="none">curl -X GET http://127.0.0.1:5984/demo/8843faaf0b831d364278331bc3001bd8</userinput> +{"_id":"8843faaf0b831d364278331bc3001bd8", + "_rev":"1-33b9fbce46930280dab37d672bbc8bb9", + "company":"Example, Inc."}</programlisting> + + <para> + The API samples in the <xref linkend="couchdb-api-basics"/> show + the HTTP command, URL and any payload information that needs to be + submitted (and the expected return value). All of these examples + can be reproduced using <command moreinfo="none">curl</command> with the + command-line examples shown above. + </para> + + </section> + +</chapter> + + <chapter id="couchdb-single-features"> + + <title>Features and Functionality</title> + + <para> + + </para> + + <section id="couchdb-single-features-httprange"> + + <title>HTTP Range Requests</title> + + <para> + HTTP allows you to specify byte ranges for requests. This allows + the implementation of resumable downloads and skippable audio and + video streams alike. The following example uses a text file to + make the range request process easier. + </para> + +<programlisting format="linespecific">shell> <userinput moreinfo="none">cat file.txt</userinput> +My hovercraft is full of eels!</programlisting> + + <para> + Uploading this as an attachment to a <literal moreinfo="none">text</literal> + database using <command moreinfo="none">curl</command>: + </para> + +<programlisting format="linespecific">shell> <userinput moreinfo="none">curl -X PUT http://127.0.0.1:5984/test/doc/file.txt \ + -H "Content-Type: application/octet-stream" -d@file.txt</userinput> +{"ok":true,"id":"doc","rev":"1-287a28fa680ae0c7fb4729bf0c6e0cf2"}</programlisting> + + <para> + Requesting the whole file works as normal: + </para> + +<programlisting format="linespecific">shell> <userinput moreinfo="none">curl -X GET http://127.0.0.1:5984/test/doc/file.txt</userinput> +My hovercraft is full of eels!</programlisting> + + <para> + But to retrieve only the first 13 bytes using + <command moreinfo="none">curl</command>: + </para> + +<programlisting format="linespecific">shell> <userinput moreinfo="none">curl -X GET http://127.0.0.1:5984/test/doc/file.txt -H "Range: bytes=0-12"</userinput> +My hovercraft</programlisting> + + <para> + HTTP supports many ways to specify single and even multiple byte + rangers. See + <ulink url="http://tools.ietf.org/html/rfc2616#section-14.27">RFC + 2616</ulink>. + </para> + + <note> + <para> + Databases that have been created with CouchDB 1.0.2 or earlier + will support range requests in 1.1.0, but they are using a + less-optimal algorithm. If you plan to make heavy use of this + feature, make sure to compact your database with CouchDB 1.1.0 + to take advantage of a better algorithm to find byte ranges. + </para> + </note> + + </section> + + <section id="couchdb-single-features-proxying"> + + <title>HTTP Proxying</title> + + <para> + The HTTP proxy feature makes it easy to map and redirect different + content through your CouchDB URL. The proxy works by mapping a + pathname and passing all content after that prefix through to the + configured proxy address. + </para> + + <para> + Configuration of the proxy redirect is handled through the + <literal moreinfo="none">[httpd_global_handlers]</literal> section of the CouchDB + configuration file (typically <filename moreinfo="none">local.ini</filename>). The + format is: + </para> + +<programlisting format="linespecific">[httpd_global_handlers] +PREFIX = {couch_httpd_proxy, handle_proxy_req, <<"DESTINATION">>}</programlisting> + + <para> + Where: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal moreinfo="none">PREFIX</literal> + </para> + + <para> + Is the string that will be matched. The string can be any + valid qualifier, although to ensure that existing database + names are not overridden by a proxy configuration, you can use + an underscore prefix. + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">DESTINATION</literal> + </para> + + <para> + The fully-qualified URL to which the request should be sent. + The destination must include the <literal moreinfo="none">http</literal> + prefix. The content is used verbatim in the original request, + so you can also forward to servers on different ports and to + specific paths on the target host. + </para> + </listitem> + + </itemizedlist> + + <para> + The proxy process then translates requests of the form: + </para> + +<programlisting format="linespecific">http://couchdb:5984/PREFIX/path</programlisting> + + <para> + To: + </para> + +<programlisting format="linespecific">DESTINATION/path</programlisting> + + <note> + <para> + Everything after <literal moreinfo="none">PREFIX</literal> including the + required forward slash will be appended to the + <literal moreinfo="none">DESTINATION</literal>. + </para> + </note> + + <para> + The response is then communicated back to the original client. + </para> + + <para> + For example, the following configuration: + </para> + +<programlisting format="linespecific">_google = {couch_httpd_proxy, handle_proxy_req, <<"http://www.google.com">>}</programlisting> + + <para> + Would forward all requests for + <literal moreinfo="none">http://couchdb:5984/_google</literal> to the Google + website. + </para> + + <para> + The service can also be used to forward to related CouchDB + services, such as Lucene: + </para> + +<programlisting format="linespecific">[httpd_global_handlers] +_fti = {couch_httpd_proxy, handle_proxy_req, <<"http://127.0.0.1:5985">>}</programlisting> + + <note> + <para> + The proxy service is basic. If the request is not identified by + the <literal moreinfo="none">DESTINATION</literal>, or the remainder of the + <literal moreinfo="none">PATH</literal> specification is incomplete, the + original request URL is interpreted as if the + <literal moreinfo="none">PREFIX</literal> component of that URL does not exist. + </para> + + <para> + For example, requesting + <literal moreinfo="none">http://couchdb:5984/_intranet/media</literal> when + <filename moreinfo="none">/media</filename> on the proxy destination does not + exist, will cause the request URL to be interpreted as + <literal moreinfo="none">http://couchdb:5984/media</literal>. Care should be + taken to ensure that both requested URLs and destination URLs + are able to cope + </para> + </note> + + </section> + + <section id="couchdb-single-features-commonjs"> + + <title>CommonJS support for map functions</title> + + <para> + CommonJS support allows you to use CommonJS notation inside + <methodname>map</methodname> and <methodname>reduce</methodname> + functions, but only of libraries that are stored inside the views + part of the design doc. + </para> + + <para> + So you could continue to access CommonJS code in design_doc.foo, + from your list functions etc, but we'd add the ability to require + CommonJS modules within map and reduce, but only from + <filename moreinfo="none">design_doc.views.lib</filename>. + </para> + + <para> + There's no worry here about namespace collisions, as Couch just + plucks <literal moreinfo="none">views.*.map</literal> and + <literal moreinfo="none">views.*.reduce</literal> out of the design doc. So you + could have a view called <literal moreinfo="none">lib</literal> if you wanted, and + still have CommonJS stored in <literal moreinfo="none">views.lib.sha1</literal> + and <literal moreinfo="none">views.lib.stemmer</literal> if you wanted. + </para> + + <para> + The implementation is simplified by enforcing that CommonJS + modules to be used in <methodname>map</methodname> functions be + stored in views.lib. + </para> + + <para> + A sample design doc (taken from the test suite in Futon) is below: + </para> + +<programlisting format="linespecific">{ + "views" : { + "lib" : { + "baz" : "exports.baz = 'bam';", + "foo" : { + "zoom" : "exports.zoom = 'yeah';", + "boom" : "exports.boom = 'ok';", + "foo" : "exports.foo = 'bar';" + } + }, + "commonjs" : { + "map" : "function(doc) { emit(null, require('views/lib/foo/boom').boom)}" + } + }, + "_id" : "_design/test" +}</programlisting> + + <para> + The <literal moreinfo="none">require()</literal> statement is relative to the + design document, but anything loaded form outside of + <literal moreinfo="none">views/lib</literal> will fail. + </para> + + </section> + + <section id="couchdb-single-features-etag"> + + <title>Granular ETag support</title> + + <para> + ETags have been assigned to a map/reduce group (the collection of + views in a single design document). Any change to any of the + indexes for those views would generate a new ETag for all view + URL's in a single design doc, even if that specific view's results + had not changed. + </para> + + <para> + In CouchDB 1.1 each <literal moreinfo="none">_view</literal> URL has it's own ETag + which only gets updated when changes are made to the database that + effect that index. If the index for that specific view does not + change, that view keeps the original ETag head (therefore sending + back 304 Not Modified more often). + </para> + + </section> + +</chapter> + + <chapter id="couchdb-single-replication"> + + <title>Replication</title> + + <para> + + </para> + + <section id="couchdb-single-replication-replicatordb"> + + <title>Replicator Database</title> + + <para> + A database where you + <literal moreinfo="none">PUT</literal>/<literal moreinfo="none">POST</literal> documents to + trigger replications and you <literal moreinfo="none">DELETE</literal> to cancel + ongoing replications. These documents have exactly the same + content as the JSON objects we used to <literal moreinfo="none">POST</literal> to + <literal moreinfo="none">_replicate</literal> (fields <literal moreinfo="none">source</literal>, + <literal moreinfo="none">target</literal>, <literal moreinfo="none">create_target</literal>, + <literal moreinfo="none">continuous</literal>, <literal moreinfo="none">doc_ids</literal>, + <literal moreinfo="none">filter</literal>, <literal moreinfo="none">query_params</literal>. + </para> + + <para> + Replication documents can have a user defined + <literal moreinfo="none">_id</literal>. Design documents (and + <literal moreinfo="none">_local</literal> documents) added to the replicator + database are ignored. + </para> + + <para> + The default name of this database is + <literal moreinfo="none">_replicator</literal>. The name can be changed in the + <filename moreinfo="none">local.ini</filename> configuration, section + <literal moreinfo="none">[replicator]</literal>, parameter <literal moreinfo="none">db</literal>. + </para> + + <section id="couchdb-single-replication-replicatordb-basics"> + + <title>Basics</title> + + <para> + Let's say you PUT the following document into _replicator: + </para> + +<programlisting format="linespecific">{ + "_id": "my_rep", + "source": "http://myserver.com:5984/foo", + "target": "bar", + "create_target": true +}</programlisting> + + <para> + In the couch log you'll see 2 entries like these: + </para> + +<programlisting format="linespecific">[Thu, 17 Feb 2011 19:43:59 GMT] [info] [<0.291.0>] Document `my_rep` triggered replication `c0ebe9256695ff083347cbf95f93e280+create_target` +[Thu, 17 Feb 2011 19:44:37 GMT] [info] [<0.124.0>] Replication `c0ebe9256695ff083347cbf95f93e280+create_target` finished (triggered by document `my_rep`)</programlisting> + + <para> + As soon as the replication is triggered, the document will be + updated by CouchDB with 3 new fields: + </para> + +<programlisting format="linespecific">{ + "_id": "my_rep", + "source": "http://myserver.com:5984/foo", + "target": "bar", + "create_target": true, + "_replication_id": "c0ebe9256695ff083347cbf95f93e280", + "_replication_state": "triggered", + "_replication_state_time": 1297974122 +}</programlisting> + + <para> + Special fields set by the replicator start with the prefix + <literal moreinfo="none">_replication_</literal>. + </para> + + <itemizedlist> + + <listitem> + <para> + <literal moreinfo="none">_replication_id</literal> + </para> + + <para> + The ID internally assigned to the replication. This is also + the ID exposed by <literal moreinfo="none">/_active_tasks</literal>. + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">_replication_state</literal> + </para> + + <para> + The current state of the replication. + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">_replication_state_time</literal> + </para> + + <para> + A Unix timestamp (number of seconds since 1 Jan 1970) that + tells us when the current replication state (marked in + <literal moreinfo="none">_replication_state</literal>) was set. + </para> + </listitem> + + </itemizedlist> + + <para> + When the replication finishes, it will update the + <literal moreinfo="none">_replication_state</literal> field (and + <literal moreinfo="none">_replication_state_time</literal>) with the value + <literal moreinfo="none">completed</literal>, so the document will look like: + </para> + +<programlisting format="linespecific">{ + "_id": "my_rep", + "source": "http://myserver.com:5984/foo", + "target": "bar", + "create_target": true, + "_replication_id": "c0ebe9256695ff083347cbf95f93e280", + "_replication_state": "completed", + "_replication_state_time": 1297974122 +}</programlisting> + + <para> + When an error happens during replication, the + <literal moreinfo="none">_replication_state</literal> field is set to + <literal moreinfo="none">error</literal> (and + <literal moreinfo="none">_replication_state</literal> gets updated of course). + </para> + + <para> + When you PUT/POST a document to the + <literal moreinfo="none">_replicator</literal> database, CouchDB will attempt to + start the replication up to 10 times (configurable under + <literal moreinfo="none">[replicator]</literal>, parameter + <literal moreinfo="none">max_replication_retry_count</literal>). If it fails on + the first attempt, it waits 5 seconds before doing a second + attempt. If the second attempt fails, it waits 10 seconds before + doing a third attempt. If the third attempt fails, it waits 20 + seconds before doing a fourth attempt (each attempt doubles the + previous wait period). When an attempt fails, the Couch log will + show you something like: + </para> + +<programlisting format="linespecific">[error] [<0.149.0>] Error starting replication `67c1bb92010e7abe35d7d629635f18b6+create_target` (document `my_rep_2`): {db_not_found,<<"could not open http://myserver:5986/foo/">></programlisting> + + <note> + <para> + The <literal moreinfo="none">_replication_state</literal> field is only set to + <literal moreinfo="none">error</literal> when all the attempts were + unsuccessful. + </para> + </note> + + <para> + There are only 3 possible values for the + <literal moreinfo="none">_replication_state</literal> field: + <literal moreinfo="none">triggered</literal>, <literal moreinfo="none">completed</literal> and + <literal moreinfo="none">error</literal>. Continuous replications never get + their state set to <literal moreinfo="none">completed</literal>. + </para> + + </section> + + <section id="couchdb-single-replication-replicatordb-docsame"> + + <title>Documents describing the same replication</title> + + <para> + Lets suppose 2 documents are added to the + <literal moreinfo="none">_replicator</literal> database in the following order: + </para> + +<programlisting format="linespecific">{ + "_id": "doc_A", + "source": "http://myserver.com:5984/foo", + "target": "bar" +}</programlisting> + + <para> + and + </para> + +<programlisting format="linespecific">{ + "_id": "doc_B", + "source": "http://myserver.com:5984/foo", + "target": "bar" +}</programlisting> + + <para> + Both describe exactly the same replication (only their + <literal moreinfo="none">_ids</literal> differ). In this case document + <literal moreinfo="none">doc_A</literal> triggers the replication, getting + updated by CouchDB with the fields + <literal moreinfo="none">_replication_state</literal>, + <literal moreinfo="none">_replication_state_time</literal> and + <literal moreinfo="none">_replication_id</literal>, just like it was described + before. Document <literal moreinfo="none">doc_B</literal> however, is only + updated with one field, the <literal moreinfo="none">_replication_id</literal> + so it will look like this: + </para> + +<programlisting format="linespecific">{ + "_id": "doc_B", + "source": "http://myserver.com:5984/foo", + "target": "bar", + "_replication_id": "c0ebe9256695ff083347cbf95f93e280" +}</programlisting> + + <para> + While document <literal moreinfo="none">doc_A</literal> will look like this: + </para> + +<programlisting format="linespecific">{ + "_id": "doc_A", + "source": "http://myserver.com:5984/foo", + "target": "bar", + "_replication_id": "c0ebe9256695ff083347cbf95f93e280", + "_replication_state": "triggered", + "_replication_state_time": 1297974122 +}</programlisting> + + <para> + Note that both document get exactly the same value for the + <literal moreinfo="none">_replication_id</literal> field. This way you can + identify which documents refer to the same replication - you can + for example define a view which maps replication IDs to document + IDs. + </para> + + </section> + + <section id="couchdb-single-replication-replicatordb-cancel"> + + <title>Canceling replications</title> + + <para> + To cancel a replication simply <literal moreinfo="none">DELETE</literal> the + document which triggered the replication. The Couch log will + show you an entry like the following: + </para> + +<programlisting format="linespecific">[Thu, 17 Feb 2011 20:16:29 GMT] [info] [<0.125.0>] Stopped replication `c0ebe9256695ff083347cbf95f93e280+continuous+create_target` because replication document `doc_A` was deleted</programlisting> + + <note> + <para> + You need to <literal moreinfo="none">DELETE</literal> the document that + triggered the replication. <literal moreinfo="none">DELETE</literal>ing + another document that describes the same replication but did + not trigger it, will not cancel the replication. + </para> + </note> + + </section> + + <section id="couchdb-single-replication-replicatordb-restart"> + + <title>Server restart</title> + + <para> + When CouchDB is restarted, it checks its + <literal moreinfo="none">_replicator</literal> database and restarts any + replication that is described by a document that either has its + <literal moreinfo="none">_replication_state</literal> field set to + <literal moreinfo="none">triggered</literal> or it doesn't have yet the + <literal moreinfo="none">_replication_state</literal> field set. + </para> + + <note> + <para> + Continuous replications always have a + <literal moreinfo="none">_replication_state</literal> field with the value + <literal moreinfo="none">triggered</literal>, therefore they're always + restarted when CouchDB is restarted. + </para> + </note> + + </section> + + <section id="couchdb-single-replication-replicatordb-changing"> + + <title>Changing the Replicator Database</title> + + <para> + Imagine your replicator database (default name is _replicator) + has the two following documents that represent pull replications + from servers A and B: + </para> + +<programlisting format="linespecific">{ + "_id": "rep_from_A", + "source": "http://aserver.com:5984/foo", + "target": "foo_a", + "continuous": true, + "_replication_id": "c0ebe9256695ff083347cbf95f93e280", + "_replication_state": "triggered", + "_replication_state_time": 1297971311 +} +{ + "_id": "rep_from_B", + "source": "http://bserver.com:5984/foo", + "target": "foo_b", + "continuous": true, + "_replication_id": "231bb3cf9d48314eaa8d48a9170570d1", + "_replication_state": "triggered", + "_replication_state_time": 1297974122 +}</programlisting> + + <para> + Now without stopping and restarting CouchDB, you change the name + of the replicator database to + <literal moreinfo="none">another_replicator_db</literal>: + </para> + +<programlisting format="linespecific">$ curl -X PUT http://localhost:5984/_config/replicator/db -d '"another_replicator_db"' +"_replicator"</programlisting> + + <para> + As soon as this is done, both pull replications defined before, + are stopped. This is explicitly mentioned in CouchDB's log: + </para> + +<programlisting format="linespecific">[Fri, 11 Mar 2011 07:44:20 GMT] [info] [<0.104.0>] Stopping all ongoing replications because the replicator database was deleted or changed +[Fri, 11 Mar 2011 07:44:20 GMT] [info] [<0.127.0>] 127.0.0.1 - - PUT /_config/replicator/db 200</programlisting> + + <para> + Imagine now you add a replication document to the new replicator + database named <literal moreinfo="none">another_replicator_db</literal>: + </para> + +<programlisting format="linespecific">{ + "_id": "rep_from_X", + "source": "http://xserver.com:5984/foo", + "target": "foo_x", + "continuous": true +}</programlisting> + + <para> + From now own you have a single replication going on in your + system: a pull replication pulling from server X. Now you change + back the replicator database to the original one + <literal moreinfo="none">_replicator</literal>: + </para> + +<programlisting format="linespecific">$ curl -X PUT http://localhost:5984/_config/replicator/db -d '"_replicator"' +"another_replicator_db"</programlisting> + + <para> + Immediately after this operation, the replication pulling from + server X will be stopped and the replications defined in the + _replicator database (pulling from servers A and B) will be + resumed. + </para> + + <para> + Changing again the replicator database to + <literal moreinfo="none">another_replicator_db</literal> will stop the pull + replications pulling from servers A and B, and resume the pull + replication pulling from server X. + </para> + + </section> + + <section id="couchdb-single-replication-replicatordb-replicating"> + + <title>Replicating the replicator database</title> + + <para> + Imagine you have in server C a replicator database with the two + following pull replication documents in it: + </para> + +<programlisting format="linespecific">{ + "_id": "rep_from_A", + "source": "http://aserver.com:5984/foo", + "target": "foo_a", + "continuous": true, + "_replication_id": "c0ebe9256695ff083347cbf95f93e280", + "_replication_state": "triggered", + "_replication_state_time": 1297971311 +} +{ + "_id": "rep_from_B", + "source": "http://bserver.com:5984/foo", + "target": "foo_b", + "continuous": true, + "_replication_id": "231bb3cf9d48314eaa8d48a9170570d1", + "_replication_state": "triggered", + "_replication_state_time": 1297974122 +}</programlisting> + + <para> + Now you would like to have the same pull replications going on + in server D, that is, you would like to have server D pull + replicating from servers A and B. You have two options: + </para> + + <itemizedlist> + + <listitem> + <para> + Explicitly add two documents to server's D replicator + database + </para> + </listitem> + + <listitem> + <para> + Replicate server's C replicator database into server's D + replicator database + </para> + </listitem> + + </itemizedlist> + + <para> + Both alternatives accomplish exactly the same goal. + </para> + + </section> + + <section id="couchdb-single-replication-replicatordb-delegations"> + + <title>Delegations</title> + + <para> + Replication documents can have a custom + <literal moreinfo="none">user_ctx</literal> property. This property defines the + user context under which a replication runs. For the old way of + triggering replications (POSTing to + <literal moreinfo="none">/_replicate/</literal>), this property was not needed + (it didn't exist in fact) - this is because at the moment of + triggering the replication it has information about the + authenticated user. With the replicator database, since it's a + regular database, the information about the authenticated user + is only present at the moment the replication document is + written to the database - the replicator database implementation + is like a _changes feed consumer (with + <literal moreinfo="none">?include_docs=true</literal>) that reacts to what was + written to the replicator database - in fact this feature could + be implemented with an external script/program. This + implementation detail implies that for non admin users, a + <literal moreinfo="none">user_ctx</literal> property, containing the user's name + and a subset of his/her roles, must be defined in the + replication document. This is ensured by the document update + validation function present in the default design document of + the replicator database. This validation function also ensure + that a non admin user can set a user name property in the + <literal moreinfo="none">user_ctx</literal> property that doesn't match his/her + own name (same principle applies for the roles). + </para> + + <para> + For admins, the <literal moreinfo="none">user_ctx</literal> property is + optional, and if it's missing it defaults to a user context with + name null and an empty list of roles - this mean design + documents will not be written to local targets. If writing + design documents to local targets is desired, the a user context + with the roles <literal moreinfo="none">_admin</literal> must be set explicitly. + </para> + + <para> + Also, for admins the <literal moreinfo="none">user_ctx</literal> property can be + used to trigger a replication on behalf of another user. This is + the user context that will be passed to local target database + document validation functions. + </para> + + <note> + <para> + The <literal moreinfo="none">user_ctx</literal> property only has effect for + local endpoints. + </para> + </note> + + <para> + Example delegated replication document: + </para> + +<programlisting format="linespecific">{ + "_id": "my_rep", + "source": "http://bserver.com:5984/foo", + "target": "bar", + "continuous": true, + "user_ctx": { + "name": "joe", + "roles": ["erlanger", "researcher"] + } +}</programlisting> + + <para> + As stated before, for admins the user_ctx property is optional, + while for regular (non admin) users it's mandatory. When the + roles property of <literal moreinfo="none">user_ctx</literal> is missing, it + defaults to the empty list <literal moreinfo="none">[ ]</literal>. + </para> + + </section> + + </section> + +</chapter> + + + + <chapter id="couchdb-api-basics"> + + <title>CouchDB API</title> + + <para> + The CouchDB API is the primary method of interfacing to a CouchDB + instance. Requests are made using HTTP and requests are used to + request information from the database, store new data, and perform + views and formatting of the information stored within the documents. + </para> + + <para> + Requests to the API can be categorised by the different areas of the + CouchDB system that you are accessing, and the HTTP method used to + send the request. Different methods imply different operations, for + example retrieval of information from the database is typically + handled by the <literal moreinfo="none">GET</literal> operation, while updates are + handled by either a <literal moreinfo="none">POST</literal> or + <literal moreinfo="none">PUT</literal> request. There are some differences between + the information that must be supplied for the different methods. For + a guide to the basic HTTP methods and request structure, see + <xref linkend="couchdb-api-introduction-requests"/>. + </para> + + <para> + For nearly all operations, the submitted data, and the returned data + structure, is defined within a JavaScript Object Notation (JSON) + object. Basic information on the content and data types for JSON are + provided in <xref linkend="couchdb-api-introduction-json"/>. + </para> + + <para> + Errors when accessing the CouchDB API are reported using standard + HTTP Status Codes. A guide to the generic codes returned by CouchDB + are provided in + <xref linkend="couchdb-api-introduction-returncodes"/>. + </para> + + <para> + When accessing specific areas of the CouchDB API, specific + information and examples on the HTTP methods and request, JSON + structures, and error codes are provided. For a guide to the + different areas of the API, see + <xref linkend="couchdb-api-overview"/>. + </para> + + <section id="couchdb-api-introduction-requests"> + + <title>Request Format and Responses</title> + + <para> + CouchDB supports the following HTTP request methods: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal moreinfo="none">GET</literal> + </para> + + <para> + Request the specified item. As with normal HTTP requests, the + format of the URL defines what is returned. With CouchDB this + can include static items, database documents, and + configuration and statistical information. In most cases the + information is returned in the form of a JSON document. + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">HEAD</literal> + </para> + + <para> + The <literal moreinfo="none">HEAD</literal> method is used to get the HTTP + header of a <literal moreinfo="none">GET</literal> request without the body of + the response. + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">POST</literal> + </para> + + <para> + Upload data. Within CouchDB <literal moreinfo="none">POST</literal> is used to + set values, including uploading documents, setting document + values, and starting certain administration commands. + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">PUT</literal> + </para> + + <para> + Used to put a specified resource. In CouchDB + <literal moreinfo="none">PUT</literal> is used to create new objects, + including databases, documents, views and design documents. + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">DELETE</literal> + </para> + + <para> + Deletes the specified resource, including documents, views, + and design documents. + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">COPY</literal> + </para> + + <para> + A special method that can be used to copy documents and + objects. + </para> + </listitem> + + </itemizedlist> + + <para> + If you use the an unsupported HTTP request type with a URL that + does not support the specified type, a 405 error will be returned, + listing the supported HTTP methods. For example: + </para> + +<programlisting format="linespecific">{ + "error":"method_not_allowed", + "reason":"Only GET,HEAD allowed" +}</programlisting> + + + + <para> + The CouchDB design document API and the functions when returning + HTML (for example as part of a show or list) enables you to + include custom HTTP headers through the <literal moreinfo="none">headers</literal> + block of the return object. For more information, see + <xref linkend="couchdb-api-functional"/>. + </para> + + </section> + + <section id="couchdb-api-introduction-request-header"> + + <title>HTTP Headers</title> + + <para> + Because CouchDB uses HTTP for all communication, you need to + ensure that the correct HTTP headers are supplied (and processed + on retrieval) so that you get the right format and encoding. + Different environments and clients will be more or less strict on + the effect of these HTTP headers (especially when not present). + Where possible you should be as specific as possible. + </para> + + <section id="couchdb-api-introduction-request-header-request"> + + <title>Request Headers</title> + + <itemizedlist> + + <listitem> + <para> + <literal moreinfo="none">Content-type</literal> + </para> + + <para> + Specifies the content type of the information being supplied + within the request. The specification uses MIME type + specifications. For the majority of requests this will be + JSON (<literal moreinfo="none">application/json</literal>). For some + settings the MIME type will be plain text. When uploading + attachments it should be the corresponding MIME type for the + attachment or binary + (<literal moreinfo="none">application/octet-stream</literal>). + </para> + + <para> + The use of the <literal moreinfo="none">Content-type</literal> on a request + is highly recommended. + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">Accept</literal> + </para> + + <para> + Specifies the list of accepted data types to be returned by + the server (i.e. that are accepted/understandable by the + client). The format should be a list of one or more MIME + types, separated by colons. + </para> + + <para> + For the majority of requests the definition should be for + JSON data (<literal moreinfo="none">application/json</literal>). For + attachments you can either specify the MIME type explicitly, + or use <literal moreinfo="none">*/*</literal> to specify that all file types + are supported. If the <literal moreinfo="none">Accept</literal> header is + not supplied, then the <literal moreinfo="none">*/*</literal> MIME type is + assumed (i.e. client accepts all formats). + </para> + + <para> + The use of <literal moreinfo="none">Accept</literal> in queries for CouchDB + is not required, but is highly recommended as it helps to + ensure that the data returned can be processed by the + client. + </para> + + <para> + If you specify a data type using the + <literal moreinfo="none">Accept</literal> header, CouchDB will honor the + specified type in the <literal moreinfo="none">Content-type</literal> header + field returned. For example, if you explicitly request + <literal moreinfo="none">application/json</literal> in the + <literal moreinfo="none">Accept</literal> of a request, the returned HTTP + headers will use the value in the returned + <literal moreinfo="none">Content-type</literal> field. + </para> + + <para> + For example, when sending a request without an explicit + <literal moreinfo="none">Accept</literal> header, or when specifying + <literal moreinfo="none">*/*</literal>: + </para> + +<programlisting format="linespecific">GET /recipes HTTP/1.1 +Host: couchdb:5984 +Accept: */*</programlisting> + + <para> + The returned headers are: + </para> + +<programlisting format="linespecific">Server: CouchDB/1.0.1 (Erlang OTP/R13B) +Date: Thu, 13 Jan 2011 13:39:34 GMT +Content-Type: text/plain;charset=utf-8 +Content-Length: 227 +Cache-Control: must-revalidate</programlisting> + + <para> + Note that the returned content type is + <literal moreinfo="none">text/plain</literal> even though the information + returned by the request is in JSON format. + </para> + + <para> + Explicitly specifying the <literal moreinfo="none">Accept</literal> header: + </para> + +<programlisting format="linespecific">GET /recipes HTTP/1.1 +Host: couchdb:5984 +Accept: application/json</programlisting> + + <para> + The headers returned include the + <literal moreinfo="none">application/json</literal> content type: + </para> + +<programlisting format="linespecific">Server: CouchDB/1.0.1 (Erlang OTP/R13B) +Date: Thu, 13 Jan 2011 13:40:11 GMT +Content-Type: application/json +Content-Length: 227 +Cache-Control: must-revalidate</programlisting> + </listitem> + + </itemizedlist> + + </section> + + <section id="couchdb-api-introduction-request-header-response"> + + <title>Response Headers</title> + + <para> + Response headers are returned by the server when sending back + content and include a number of different header fields, many of + which are standard HTTP response header and have no significance + to CouchDB operation. The list of response headers important to + CouchDB are listed below. + </para> + + <itemizedlist> + + <listitem> + <para> + <literal moreinfo="none">Content-type</literal> + </para> + + <para> + Specifies the MIME type of the returned data. For most + request, the returned MIME type is + <literal moreinfo="none">text/plain</literal>. All text is encoded in + Unicode (UTF-8), and this is explicitly stated in the + returned <literal moreinfo="none">Content-type</literal>, as + <literal moreinfo="none">text/plain;charset=utf-8</literal>. + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">Cache-control</literal> + </para> + + <para> + The cache control HTTP response header provides a suggestion + for client caching mechanisms on how to treat the returned + information. CouchDB typically returns the + <literal moreinfo="none">must-revalidate</literal>, which indicates that the + information should be revalidated if possible. This is used + to ensure that the dynamic nature of the content is + correctly updated. + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">Content-length</literal> + </para> + + <para> + The length (in bytes) of the returned content. + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">Etag</literal> + </para> + + <para> + The <literal moreinfo="none">Etag</literal> HTTP header field is used to + show the revision for a document. + </para> + </listitem> + + </itemizedlist> + + </section> + + </section> + + <section id="couchdb-api-introduction-json"> + + <title>JSON Basics</title> + + <para> + The majority of requests and responses to CouchDB use the + JavaScript Object Notation (JSON) for formatting the content and + structure of the data and responses. + </para> + + <para> + JSON is used because it is the simplest and easiest to use + solution for working with data within a web browser, as JSON + structures can be evaluated and used as JavaScript objects within + the web browser environment. JSON also integrates with the + server-side JavaScript used within CouchDB. + </para> + + <para> + JSON supports the same basic types as supported by JavaScript, + these are: + </para> + + <itemizedlist> + + <listitem> + <para> + Number (either integer or floating-point). + </para> + </listitem> + + <listitem> + <para> + String; this should be enclosed by double-quotes and supports + Unicode characters and backslash escaping. For example: + </para> + +<programlisting format="linespecific">"A String"</programlisting> + </listitem> + + <listitem> + <para> + Boolean - a <literal moreinfo="none">true</literal> or + <literal moreinfo="none">false</literal> value. You can use these strings + directly. For example: + </para> + +<programlisting format="linespecific">{ "value": true}</programlisting> + </listitem> + + <listitem> + <para> + Array - a list of values enclosed in square brackets. For + example: + </para> + +<programlisting format="linespecific">["one", "two", "three"]</programlisting> + </listitem> + + <listitem> + <para> + Object - a set of key/value pairs (i.e. an associative array, + or hash). The key must be a string, but the value can be any + of the supported JSON values. For example: + </para> + +<programlisting format="linespecific">{ + "servings" : 4, + "subtitle" : "Easy to make in advance, and then cook when ready", + "cooktime" : 60, + "title" : "Chicken Coriander" +}</programlisting> + + <para> + In CouchDB, the JSON object is used to represent a variety of + structures, including the main CouchDB document. + </para> + </listitem> + + </itemizedlist> + + <para> + Parsing JSON into a JavaScript object is supported through the + <literal moreinfo="none">eval()</literal> function in JavaScript, or through + various libraries that will perform the parsing of the content + into a JavaScript object for you. Libraries for parsing and + generating JSON are available in many languages, including Perl, + Python, Ruby, Erlang and others. + </para> + + <warning> + <para> + Care should be taken to ensure that your JSON structures are + valid, invalid structures will cause CouchDB to return an HTTP + status code of 500 (server error). See + <xref linkend="couchdb-api-introduction-returncode-500"/> + . + </para> + </warning> + + </section> + + <section id="couchdb-api-introduction-returncodes"> + + <title>HTTP Status Codes</title> + + <para> + With the interface to CouchDB working through HTTP, error codes + and statuses are reported using a combination of the HTTP status + code number, and corresponding data in the body of the response + data. + </para> + + <para> + A list of the error codes returned by CouchDB, and generic + descriptions of the related errors are provided below. The meaning + of different status codes for specific request types are provided + in the corresponding API call reference. + </para> + + <itemizedlist> + + <listitem> + <para id="couchdb-api-introduction-returncode-200"> + <literal moreinfo="none">200 - OK</literal> + </para> + + <para> + Request completed successfully. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-201"> + <literal moreinfo="none">201 - Created</literal> + </para> + + <para> + Document created successfully. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-202"> + <literal moreinfo="none">202 - Accepted</literal> + </para> + + <para> + Request has been accepted, but the corresponding operation may + not have completed. This is used for background operations, + such as database compaction. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-304"> + <literal moreinfo="none">304 - Not Modified</literal> + </para> + + <para> + The additional content requested has not been modified. This + is used with the ETag system to identify the version of + information returned. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-400"> + <literal moreinfo="none">400 - Bad Request</literal> + </para> + + <para> + Bad request structure. The error can indicate an error with + the request URL, path or headers. Differences in the supplied + MD5 hash and content also trigger this error, as this may + indicate message corruption. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-401"> + <literal moreinfo="none">401 - Unauthorized</literal> + </para> + + <para> + The item requested was not available using the supplied + authorization, or authorization was not supplied. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-403"> + <literal moreinfo="none">403 - Forbidden</literal> + </para> + + <para> + The requested item or operation is forbidden. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-404"> + <literal moreinfo="none">404 - Not Found</literal> + </para> + + <para> + The requested content could not be found. The content will + include further information, as a JSON object, if available. + The structure will contain two keys, <literal moreinfo="none">error</literal> + and <literal moreinfo="none">reason</literal>. For example: + </para> + +<programlisting format="linespecific">{"error":"not_found","reason":"no_db_file"}</programlisting> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-405"> + <literal moreinfo="none">405 - Resource Not Allowed</literal> + </para> + + <para> + A request was made using an invalid HTTP request type for the + URL requested. For example, you have requested a + <literal moreinfo="none">PUT</literal> when a <literal moreinfo="none">POST</literal> is + required. Errors of this type can also triggered by invalid + URL strings. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-406"> + <literal moreinfo="none">406 - Not Acceptable</literal> + </para> + + <para> + The requested content type is not supported by the server. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-409"> + <literal moreinfo="none">409 - Conflict</literal> + </para> + + <para> + Request resulted in an update conflict. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-412"> + <literal moreinfo="none">412 - Precondition Failed</literal> + </para> + + <para> + The request headers from the client and the capabilities of + the server do not match. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-415"> + <literal moreinfo="none">415 - Bad Content Type</literal> + </para> + + <para> + The content types supported, and the content type of the + information being requested or submitted indicate that the + content type is not supported. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-416"> + <literal moreinfo="none">416 - Requested Range Not Satisfiable</literal> + </para> + + <para> + The range specified in the request header cannot be satisfied + by the server. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-417"> + <literal moreinfo="none">417 - Expectation Failed</literal> + </para> + + <para> + When sending documents in bulk, the bulk load operation + failed. + </para> + </listitem> + + <listitem> + <para id="couchdb-api-introduction-returncode-500" xreflabel="HTTP Status Code 500"> + <literal moreinfo="none">500 - Internal Server Error</literal> + </para> + + <para> + The request was invalid, either because the supplied JSON was + invalid, or invalid information was supplied as part of the + request. + </para> + </listitem> + + </itemizedlist> + + </section> + + <section id="couchdb-api-overview"> + + <title>CouchDB API Overview</title> + + <para> + The components of the API URL path help determine the part of the + CouchDB server that is being accessed. The result is the structure + of the URL request both identifies and effectively describes the + area of the database you are accessing. + </para> + + <para> + As with all URLs, the individual components are separated by a + forward slash. + </para> + + <para> + As a general rule, URL components and JSON fields starting with + the <literal moreinfo="none">_</literal> (underscore) character represent a + special component or entity within the server or returned object. + For example, the URL fragment <literal moreinfo="none">/_all_dbs</literal> gets a + list of all of the databases in a CouchDB instance. + </para> + + <para> + The remainder of the URL API structure can be divided up according + to the URL structure. The different sections are divided as + follows: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal moreinfo="none">/db</literal> + </para> + + <para> + Database methods, related to adding, updating or deleting + databases, and setting database parameters and operations. For + more detailed information, see + <xref linkend="couchdb-api-db"/> . + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">/db/doc</literal> + </para> + + <para> + Document methods, those that create, store, update or delete + CouchDB documents and their attachments. For more information, + see <xref linkend="couchdb-api-dbdoc"/>. + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">/db/_local/local-doc</literal> + </para> + + <para> + Document methods, those that create, store, update or delete + CouchDB documents only within the local database. Local + documents are not synchronized with other databases. For more + information, see + <xref linkend="couchdb-api-localdb"/>. + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">/db/_design/design-doc</literal> + </para> + + <para> + Design documents provide the methods and structure for + recovering information from a CouchDB database in the form of + views, shows and lists. For more information, see + <xref linkend="couchdb-api-design"/>. + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">/_special</literal> + </para> + + <para> + Special methods that obtain or set information about the + CouchDB instance, including methods for configuring + replication, accessing the logs, and generate Universally + Unique IDs (UUIDs). For more information, see + <xref linkend="couchdb-api-misc"/>. + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">/_config</literal> + </para> + + <para> + Methods for getting, and settings, CouchDB configuration + parameters. For more information, see + <xref linkend="couchdb-api-misc"/>. + </para> + </listitem> + + </itemizedlist> + + + + </section> + +</chapter> + + <chapter id="couchdb-api-db"> + + <title>CouchDB API Server Database Methods</title> + + <para> + The Database methods provide an interface to an entire database + withing CouchDB. These are database, rather than document, level + requests. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-db-summary"><title>Database API Calls</title><tgroup cols="3"><colspec colname="method"/><colspec colname="path"/><colspec colname="desc"/><thead><row><entry>Method</entry><entry>Path</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/db</literal></entry><entry><link linkend="couchdb-api-db_db_get"> + Returns database information + </link></entry></row><row><entry><literal moreinfo="none">PUT</literal></entry><entry><literal moreinfo="none">/db</literal></entry><entry><link linkend="couchdb-api-db_db_put"> + Create a new database + </link></entry></row><row><entry><literal moreinfo="none">DELETE</literal></entry><entry><literal moreinfo="none">/db</literal></entry><entry><link linkend="couchdb-api-db_db_delete"> + Delete an existing database + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/db/_all_docs</literal></entry><entry><link linkend="couchdb-api-db_db-all-docs_get"> + Returns a built-in view of all documents in this database + </link></entry></row><row><entry><literal moreinfo="none">POST</literal></entry><entry><literal moreinfo="none">/db/_all_docs</literal></entry><entry><link linkend="couchdb-api-db_db-all-docs_post"> + Returns certain rows from the built-in view of all documents + </link></entry></row><row><entry><literal moreinfo="none">POST</literal></entry><entry><literal moreinfo="none">/db/_bulk_docs</literal></entry><entry><link linkend="couchdb-api-db_db-bulk-docs_post"> + Insert multiple documents in to the database in a single request + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/db/_changes</literal></entry><entry><link linkend="couchdb-api-db_db-changes_get"> + Returns changes for the given database + </link></entry></row><row><entry><literal moreinfo="none">POST</literal></entry><entry><literal moreinfo="none">/db/_compact</literal></entry><entry><link linkend="couchdb-api-db_db-compact_post"> + Starts a compaction for the database + </link></entry></row><row><entry><literal moreinfo="none">POST</literal></entry><entry><literal moreinfo="none">/db/_compact/design-doc</literal></entry><entry><link linkend="couchdb-api-db_db-compact-design-doc_post"> + Starts a compaction for all the views in the selected design + document + </link></entry></row><row><entry><literal moreinfo="none">POST</literal></entry><entry><literal moreinfo="none">/db/_ensure_full_commit</literal></entry><entry><link linkend="couchdb-api-db_db-ensure-full-commit_post"> + Makes sure all uncommitted changes are written and synchronized + to the disk + </link></entry></row><row><entry><literal moreinfo="none">POST</literal></entry><entry><literal moreinfo="none">/db/_missing_revs</literal></entry><entry><link linkend="couchdb-api-db_db-missing-revs_post"> + Given a list of document revisions, returns the document + revisions that do not exist in the database + </link></entry></row><row><entry><literal moreinfo="none">POST</literal></entry><entry><literal moreinfo="none">/db/_purge</literal></entry><entry><link linkend="couchdb-api-db_db-purge_post"> + Purge some historical documents entirely from database history + </link></entry></row><row><entry><literal moreinfo="none">POST</literal></entry><entry><literal moreinfo="none">/db/_revs_diff</literal></entry><entry><link linkend="couchdb-api-db_db-revs-diff_post"> + Given a list of document revisions, returns differences between + the given revisions and ones that are in the database + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/db/_revs_limit</literal></entry><entry><link linkend="couchdb-api-db_db-revs-limit_get"> + Gets the limit of historical revisions to store for a single + document in the database + </link></entry></row><row><entry><literal moreinfo="none">PUT</literal></entry><entry><literal moreinfo="none">/db/_revs_limit</literal></entry><entry><link linkend="couchdb-api-db_db-revs-limit_put"> + Sets the limit of historical revisions to store for a single + document in the database + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/db/_security</literal></entry><entry><link linkend="couchdb-api-db_db-security_get"> + Returns the special security object for the database + </link></entry></row><row><entry><literal moreinfo="none">PUT</literal></entry><entry><literal moreinfo="none">/db/_security</literal></entry><entry><link linkend="couchdb-api-db_db-security_put"> + Sets the special security object for the database + </link></entry></row><row><entry><literal moreinfo="none">POST</literal></entry><entry><literal moreinfo="none">/db/_temp_view</literal></entry><entry><link linkend="couchdb-api-db_db-temp-view_post"> + Execute a given view function for all documents and return the + result + </link></entry></row><row><entry><literal moreinfo="none">POST</literal></entry><entry><literal moreinfo="none">/db/_view_cleanup</literal></entry><entry><link linkend="couchdb-api-db_db-view-cleanup_post"> + Removes view files that are not used by any design document + </link></entry></row></tbody></tgroup></table> + + <para> + For all the database methods, the database name within the URL path + should be the database name that you wish to perform the operation + on. For example, to obtain the meta information for the database + <literal moreinfo="none">recipes</literal>, you would use the HTTP request: + </para> + +<programlisting format="linespecific">GET /recipes</programlisting> + + <para> + For clarity, the form below is used in the URL paths: + </para> + +<programlisting format="linespecific">GET /db</programlisting> + + <para> + Where <literal moreinfo="none">db</literal> is the name of any database. + </para> + + <section id="couchdb-api-db_db_get"> + + <title><literal moreinfo="none">GET /db</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /db</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /db</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Information about the database in JSON format + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>404</entry><entry namest="info" nameend="addinfo"> + The requested content could not be found. The returned content + will include further information, as a JSON object, if available. + </entry></row></tbody></tgroup></informaltable> + + <para> + Gets information about the specified database. For example, to + retrieve the information for the database + <literal moreinfo="none">recipe</literal>: + </para> + +<programlisting role="httprequest" format="linespecific">GET http://couchdb:5984/recipes +Accept: application/json</programlisting> + + <para> + The JSON response contains meta information about the database. A + sample of the JSON returned for an empty database is provided + below: + </para> + +<programlisting role="httpresponse" format="linespecific">{ + "compact_running" : false, + "committed_update_seq" : 375048, + "disk_format_version" : 5, + "disk_size" : 33153123, + "doc_count" : 18386, + "doc_del_count" : 0, + "db_name" : "recipes", + "instance_start_time" : "1290700340925570", + "purge_seq" : 10, + "update_seq" : 375048 +}</programlisting> + + <para> + The elements of the returned structure are shown in the table + below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-db-json-db-info" class="jsonstructure"><title> + CouchDB database information object + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">committed_update_seq</literal> </entry><entry> + The number of committed update. + </entry></row><row><entry><literal moreinfo="none">compact_running</literal> </entry><entry> + Set to true if the database compaction routine is operating on + this database. + </entry></row><row><entry><literal moreinfo="none">db_name</literal> </entry><entry> + The name of the database. + </entry></row><row><entry><literal moreinfo="none">disk_format_version</literal> </entry><entry> + The version of the physical format used for the data when it is + stored on disk. + </entry></row><row><entry><literal moreinfo="none">disk_size</literal> </entry><entry> + Size in bytes of the data as stored on the disk. Views indexes + are not included in the calculation. + </entry></row><row><entry><literal moreinfo="none">doc_count</literal> </entry><entry> + A count of the documents in the specified database. + </entry></row><row><entry><literal moreinfo="none">doc_del_count</literal> </entry><entry> + Number of deleted documents + </entry></row><row><entry><literal moreinfo="none">instance_start_time</literal> </entry><entry> + Timestamp of when the database was created, expressed in + milliseconds since the epoch. + </entry></row><row><entry><literal moreinfo="none">purge_seq</literal> </entry><entry> + The number of purge operations on the database. + </entry></row><row><entry><literal moreinfo="none">update_seq</literal> </entry><entry> + The current number of updates to the database. + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-api-db_db_put"> + + <title><literal moreinfo="none">PUT /db</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API PUT /db</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">PUT /db</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON success statement + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>400</entry><entry namest="info" nameend="addinfo"> + Invalid database name + </entry></row><row><entry>412</entry><entry namest="info" nameend="addinfo"> + Database already exists + </entry></row></tbody></tgroup></informaltable> + + <para> + Creates a new database. The database name must be composed of one + or more of the following characters: + </para> + + <itemizedlist> + + <listitem> + <para> + Lowercase characters (<literal moreinfo="none">a-z</literal>) + </para> + </listitem> + + <listitem> + <para> + Name must begin with a lowercase letter + </para> + </listitem> + + <listitem> + <para> + Digits (<literal moreinfo="none">0-9</literal>) + </para> + </listitem> + + <listitem> + <para> + Any of the characters <literal moreinfo="none">_</literal>, + <literal moreinfo="none">$</literal>, <literal moreinfo="none">(</literal>, + <literal moreinfo="none">)</literal>, <literal moreinfo="none">+</literal>, + <literal moreinfo="none">-</literal>, and <literal moreinfo="none">/</literal>. + </para> + </listitem> + + </itemizedlist> + + <para> + Trying to create a database that does not meet these requirements + will return an error quoting these restrictions. + </para> + + <para> + To create the database <literal moreinfo="none">recipes</literal>: + </para> + +<programlisting format="linespecific">PUT http://couchdb:5984/recipes +Content-Type: application/json</programlisting> + + <para> + The returned content contains the JSON status: + </para> + +<programlisting format="linespecific">{ + "ok" : true +}</programlisting> + + <para> + Anything should be treated as an error, and the problem should be + taken form the HTTP response code. + </para> + + </section> + + <section id="couchdb-api-db_db_delete"> + + <title><literal moreinfo="none">DELETE /db</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API DELETE /db</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">DELETE /db</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON success statement + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Database has been deleted + </entry></row><row><entry>404</entry><entry namest="info" nameend="addinfo"> + The requested content could not be found. The returned content + will include further information, as a JSON object, if available. + </entry></row></tbody></tgroup></informaltable> + + <para> + Deletes the specified database, and all the documents and + attachments contained within it. + </para> + + <para> + To delete the database <literal moreinfo="none">recipes</literal> you would send + the request: + </para> + +<programlisting format="linespecific">DELETE http://couchdb:5984/recipes +Content-Type: application/json</programlisting> + + <para> + If successful, the returned JSON will indicate success + </para> + +<programlisting format="linespecific">{ + "ok" : true +}</programlisting> + + </section> + + <section id="couchdb-api-db_db-changes_get"> + + <title><literal moreinfo="none">GET /db/_changes</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_changes</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /db/_changes</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the changes to the database + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">doc_ids</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specify the list of documents IDs to be filtered + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>json</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>none</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">feed</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Type of feed + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>normal</entry></row><row><entry/><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry/><entry><literal moreinfo="none">continuous</literal></entry><entry>Continuous (non-polling) mode</entry></row><row><entry/><entry><literal moreinfo="none">longpoll</literal></entry><entry>Long polling mode</entry></row><row><entry/><entry><literal moreinfo="none">normal</literal></entry><entry>Normal mode</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">filter</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Filter function from a design document to get updates + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>none</entry></row><row><entry/><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">heartbeat</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Period after which an empty line is sent during longpoll or + continuous + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>60000</entry></row><row><entry/><entry><emphasis role="bold">Quantity</emphasis></entry><entry>milliseconds</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">include_docs</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Include the document with the result + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">limit</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Maximum number of rows rows to return + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>none</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">since</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Start the results from changes immediately after the + specified sequence number + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>0</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">timeout</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Maximum period to wait before the response is sent + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>60000</entry></row><row><entry/><entry><emphasis role="bold">Quantity</emphasis></entry><entry>milliseconds</entry></row></tbody></tgroup></informaltable> + + <para> + Obtains a list of the changes made to the database. This can be + used to monitor for update and modifications to the database for + post processing or synchronization. There are three different + types of supported changes feeds, poll, longpoll, and continuous. + All requests are poll requests by default. You can select any feed + type explicitly using the <literal moreinfo="none">feed</literal> query argument. + </para> + + <para> + <itemizedlist> + + <listitem> + <para> + <emphasis role="bold">Poll</emphasis> + </para> + + <para> + With polling you can request the changes that have occured + since a specific sequence number. This returns the JSON + structure containing the changed document information. When + you perform a poll change request, only the changes since + the specific sequence number are returned. For example, the + query + </para> + +<programlisting format="linespecific">DELETE http://couchdb:5984/recipes/_changes +Content-Type: application/json</programlisting> + + <para> + Will get all of the changes in the database. You can request + a starting point using the <literal moreinfo="none">since</literal> query + argument and specifying the sequence number. You will need + to record the latest sequence number in your client and then + use this when making another request as the new value to the + <literal moreinfo="none">since</literal> parameter. + </para> + </listitem> + + <listitem> + <para> + <emphasis role="bold">Longpoll</emphasis> + </para> + + <para> + With long polling the request to the server will remain open + until a change is made on the database, when the changes + will be reported, and then the connection will close. The + long poll is useful when you want to monitor for changes for + a specific purpose without wanting to monitoring + continuously for changes. + </para> + + <para> + Because the wait for a change can be significant you can set + a timeout before the connection is automatically closed (the + <literal moreinfo="none">timeout</literal> argument). You can also set a + heartbeat interval (using the <literal moreinfo="none">heartbeat</literal> + query argument), which sends a newline to keep the + connection open. + </para> + </listitem> + + <listitem> + <para> + <emphasis role="bold">Continuous</emphasis> + </para> + + <para> + Continuous sends all new changes back to the client + immediately, without closing the connection. In continuous + mode the format of the changes is slightly different to + accommodate the continuous nature while ensuring that the + JSON output is still valid for each change notification. + </para> + + <para> + As with the longpoll feed type you can set both the timeout + and heartbeat intervals to ensure that the connection is + kept open for new changesand updates. + </para> + </listitem> + + </itemizedlist> + </para> + + <para> + The return structure for <literal moreinfo="none">normal</literal> and + <literal moreinfo="none">longpoll</literal> modes is a JSON array of changes + objects, and the last update sequence number. The structure is + described in the following table. + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-db_db-json-changes" class="jsonstructure"><title> + Changes information for a database + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">last_seq</literal> </entry><entry> + Last change sequence number + </entry></row><row><entry><literal moreinfo="none">results</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + Changes made to a database + </entry></row><row><entry> <literal moreinfo="none">changes</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + List of changes, field-by-field, for this document + </entry></row><row><entry> <literal moreinfo="none">id</literal> </entry><entry> + Document ID + </entry></row><row><entry> <literal moreinfo="none">seq</literal> </entry><entry> + Update sequence number + </entry></row></tbody></tgroup></table> + + <para> + The return format for <literal moreinfo="none">continuous</literal> mode the + server sends a CRLF (carriage-return, linefeed) delimited line for + each change. Each line contains the + <link linkend="table-couchdb-api-db_db-json-changes">JSON + object</link>. + </para> + + <para> + You can also request the full contents of each document change + (instead of just the change notification) by using the + <literal moreinfo="none">include_docs</literal> parameter. + </para> + + <section id="couchdb-api-db_db-changes_get-filters"> + + <title>Filtering</title> + + <para> + You can filter the contents of the changes feed in a number of + ways. The most basic way is to specify one or more document IDs + to the query. This causes the returned structure value to only + contain changes for the specified IDs. Note that the value of + this query argument should be a JSON formatted array. + </para> + + <para> + You can also filter the <literal moreinfo="none">_changes</literal> feed by + defining a filter function within a design document. The + specification for the filter is the same as for replication + filters. You specify the name of the filter function to the + <literal moreinfo="none">filter</literal> parameter, specifying the design + document name and filter name. For example: + </para> + +<programlisting format="linespecific">GET /db/_changes?filter=design_doc/filtername</programlisting> + + <para> + The <literal moreinfo="none">_changes</literal> feed can be used to watch + changes to specific document ID's or the list of + <literal moreinfo="none">_design</literal> documents in a database. If the + <literal moreinfo="none">filters</literal> parameter is set to + <literal moreinfo="none">_doc_ids</literal> a list of doc IDs can be passed in + the <option>doc_ids</option> parameter as a JSON array. + </para> + + <para> + For more information, see + <xref linkend="couchdb-single-changes-filters"/>. + </para> + + </section> + + </section> + + <section id="couchdb-api-db_db-compact_post"> + + <title><literal moreinfo="none">POST /db/_compact</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_compact</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">POST /db/_compact</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON success statement + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>202</entry><entry namest="info" nameend="addinfo"> + Compaction request has been accepted + </entry></row><row><entry>404</entry><entry namest="info" nameend="addinfo"> + The requested content could not be found. The returned content + will include further information, as a JSON object, if available. + </entry></row></tbody></tgroup></informaltable> + + <para> + Request compaction of the specified database. Compaction + compresses the disk database file by performing the following + operations: + </para> + + <itemizedlist> + + <listitem> + <para> + Writes a new version of the database file, removing any unused + sections from the new version during write. Because a new file + is temporary created for this purpose, you will need twice the + current storage space of the specified database in order for + the compaction routine to complete. + </para> + </listitem> + + <listitem> + <para> + Removes old revisions of documents from the database, up to + the per-database limit specified by the + <literal moreinfo="none">_revs_limit</literal> database parameter. See + <xref linkend="couchdb-api-db_db_get"/> . + </para> + </listitem> + + </itemizedlist> + + <para> + Compaction can only be requested on an individual database; you + cannot compact all the databases for a CouchDB instance. The + compaction process runs as a background process. + </para> + + <para> + You can determine if the compaction process is operating on a + database by obtaining the database meta information, the + <literal moreinfo="none">compact_running</literal> value of the returned database + structure will be set to true. See + <xref linkend="couchdb-api-db_db_get"/> . + </para> + + <para> + You can also obtain a list of running processes to determine + whether compaction is currently running. See + <xref linkend="couchdb-api-misc_active-tasks_get"/>. + </para> + + </section> + + <section id="couchdb-api-db_db-compact-design-doc_post"> + + <title><literal moreinfo="none">POST /db/_compact/design-doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_compact/design-doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">POST /db/_compact/design-doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON success statement + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">yes</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>202</entry><entry namest="info" nameend="addinfo"> + Compaction request has been accepted + </entry></row><row><entry>404</entry><entry namest="info" nameend="addinfo"> + The requested content could not be found. The returned content + will include further information, as a JSON object, if available. + </entry></row></tbody></tgroup></informaltable> + + <para> + Compacts the view indexes associated with the specified design + document. You can use this in place of the full database + compaction if you know a specific set of view indexes have been + affected by a recent database change. + </para> + + <para> + For example, to compact the views associated with the + <literal moreinfo="none">recipes</literal> design document: + </para> + +<programlisting format="linespecific">POST http://couchdb:5984/recipes/_compact/recipes +Content-Type: application/json</programlisting> + + <para> + CouchDB will immediately return with a status indicating that the + compaction request has been received (HTTP status code 202): + </para> + +<programlisting format="linespecific">{ + "ok" : true +}</programlisting> + + </section> + + <section id="couchdb-api-db_db-view-cleanup_post"> + + <title><literal moreinfo="none">POST /db/_view_cleanup</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_view_cleanup</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">POST /db/_view_cleanup</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON success statement + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">yes</entry></row></tbody></tgroup></informaltable> + + <para> + Cleans up the cached view output on disk for a given view. For + example: + </para> + +<programlisting format="linespecific">POST http://couchdb:5984/recipes/_view_cleanup +Content-Type: application/json</programlisting> + + <para> + If the request is successful, a basic status message us returned: + </para> + +<programlisting format="linespecific">{ + "ok" : true +}</programlisting> + + </section> + + <section id="couchdb-api-db_db-ensure-full-commit_post"> + + <title><literal moreinfo="none">POST /db/_ensure_full_commit</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_ensure_full_commit</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">POST /db/_ensure_full_commit</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON success statement + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Commit completed successfully + </entry></row><row><entry>404</entry><entry namest="info" nameend="addinfo"> + The requested content could not be found. The returned content + will include further information, as a JSON object, if available. + </entry></row></tbody></tgroup></informaltable> + + <para> + Commits any recent changes to the specified database to disk. You + should call this if you want to ensure that recent changes have + been written. For example, to commit all the changes to disk for + the database <literal moreinfo="none">recipes</literal> you would use: + </para> + +<programlisting format="linespecific">POST http://couchdb:5984/recipes/_ensure_full_commit +Content-Type: application/json</programlisting> + + <para> + This returns a status message, containing the success message and + the timestamp for when the CouchDB instance was started: + </para> + +<programlisting format="linespecific">{ + "ok" : true, + "instance_start_time" : "1288186189373361" +}</programlisting> + + + + </section> + + <section id="couchdb-api-db_db-bulk-docs_post"> + + <title><literal moreinfo="none">POST /db/_bulk_docs</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_bulk_docs</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">POST /db/_bulk_docs</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the docs and updates to be applied + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of updated documents + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>201</entry><entry namest="info" nameend="addinfo"> + Document(s) have been created or updated + </entry></row></tbody></tgroup></informaltable> + + <para> + The bulk document API allows you to create and update multiple + documents at the same time within a single request. The basic + operation is similar to creating or updating a single document, + except that you batch the document structure and information and . + When creating new documents the document ID is optional. For + updating existing documents, you must provide the document ID, + revision information, and new document values. + </para> + + <para> + For both inserts and updates the basic structure of the JSON is + the same: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-db_db-bulk-docs-json" class="jsonstructure"><title> + Bulk Documents + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">all_or_nothing</literal> (optional) </entry><entry> + Sets the database commit mode to use all-or-nothing semantics + </entry></row><row><entry><literal moreinfo="none">docs</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + Bulk Documents Document + </entry></row><row><entry> <literal moreinfo="none">_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry> <literal moreinfo="none">_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row><row><entry> <literal moreinfo="none">_deleted</literal> (optional) </entry><entry> + Whether the document should be deleted + </entry></row></tbody></tgroup></table> + + <section id="couchdb-api-db_db-bulk-docs_post-insert"> + + <title>Inserting Documents in Bulk</title> + + <para> + To insert documents in bulk into a database you need to supply a + JSON structure with the array of documents that you want to add + to the database. Using this method you can either include a + document ID, or allow the document ID to be automatically + generated. + </para> + + <para> + For example, the following inserts three new documents, two with + the supplied document IDs, and one which will have a document ID + generated: + </para> + +<programlisting format="linespecific">{ + "docs" : [ + { + "_id" : "FishStew", + "servings" : 4, + "subtitle" : "Delicious with fresh bread", + "title" : "Fish Stew" + }, + { + "_id" : "LambStew", + "servings" : 6, + "subtitle" : "Delicious with scone topping", + "title" : "Lamb Stew" + }, + { + "servings" : 8, + "subtitle" : "Delicious with suet dumplings", + "title" : "Beef Stew" + }, + ] +}</programlisting> + + <para> + The return type from a bulk insertion will be 201, with the + content of the returned structure indicating specific success or + otherwise messages on a per-document basis. + </para> + + <para> + The return structure from the example above contains a list of + the documents created, here with the combination and their + revision IDs: + </para> + +<programlisting format="linespecific">POST http://couchdb:5984/recipes/_bulk_docs +Content-Type: application/json + +[ + { + "id" : "FishStew", + "rev" : "1-9c65296036141e575d32ba9c034dd3ee", + }, + { + "id" : "LambStew", + "rev" : "1-34c318924a8f327223eed702ddfdc66d", + }, + { + "id" : "7f7638c86173eb440b8890839ff35433", + "rev" : "1-857c7cbeb6c8dd1dd34a0c73e8da3c44", + } +]</programlisting> + + <para> + The content and structure of the returned JSON will depend on + the transaction semantics being used for the bulk update; see + <xref linkend="couchdb-api-db_db-bulk-docs_post-commit"/> + for more information. Conflicts and validation errors when + updating documents in bulk must be handled separately; see + <xref linkend="couchdb-api-db_db-bulk-docs_post-errors"/>. + </para> + + </section> + + <section id="couchdb-api-db_db-bulk-docs_post-update"> + + <title>Updating Documents in Bulk</title> + + <para> + The bulk document update procedure is similar to the insertion + procedure, except that you must specify the document ID and + current revision for every document in the bulk update JSON + string. + </para> + + <para> + For example, you could send the following request: + </para> + +<programlisting format="linespecific">POST http://couchdb:5984/recipes/_bulk_docs +Content-Type: application/json + +{ + "docs" : [ + { + "_id" : "FishStew", + "_rev" : "1-9c65296036141e575d32ba9c034dd3ee", + "servings" : 4, + "subtitle" : "Delicious with freshly baked bread", + "title" : "Fish Stew" + }, + { + "_id" : "LambStew", + "_rev" : "1-34c318924a8f327223eed702ddfdc66d", + "servings" : 6, + "subtitle" : "Serve with a wholemeal scone topping", + "title" : "Lamb Stew" + }, + { + "_id" : "7f7638c86173eb440b8890839ff35433" + "_rev" : "1-857c7cbeb6c8dd1dd34a0c73e8da3c44", + "servings" : 8, + "subtitle" : "Hand-made dumplings make a great accompaniment", + "title" : "Beef Stew" + } + ] +}</programlisting> + + <para> + The return structure is the JSON of the updated documents, with + the new revision and ID information: + </para> + +<programlisting format="linespecific">[ + { + "id" : "FishStew", + "rev" : "2-e7af4c4e9981d960ecf78605d79b06d1" + }, + { + "id" : "LambStew", + "rev" : "2-0786321986194c92dd3b57dfbfc741ce" + }, + { + "id" : "7f7638c86173eb440b8890839ff35433", + "rev" : "2-bdd3bf3563bee516b96885a66c743f8e" + } +]</programlisting> + + <para> + You can optionally delete documents during a bulk update by + adding the <literal moreinfo="none">_deleted</literal> field with a value of + <literal moreinfo="none">true</literal> to each docment ID/revision combination + within the submitted JSON structure. + </para> + + <para> + The return type from a bulk insertion will be 201, with the + content of the returned structure indicating specific success or + otherwise messages on a per-document basis. + </para> + + <para> + The content and structure of the returned JSON will depend on + the transaction semantics being used for the bulk update; see + <xref linkend="couchdb-api-db_db-bulk-docs_post-commit"/> + for more information. Conflicts and validation errors when + updating documents in bulk must be handled separately; see + <xref linkend="couchdb-api-db_db-bulk-docs_post-errors"/>. + </para> + + </section> + + <section id="couchdb-api-db_db-bulk-docs_post-commit"> + + <title>Bulk Documents Transaction Semantics</title> + + <para> + CouchDB supports two different modes for updating (or inserting) + documents using the bulk documentation system. Each mode affects + both the state of the documents in the event of system failure, + and the level of conflict checking performed on each document. + The two modes are: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal moreinfo="none">non-atomic</literal> + </para> + + <para> + The default mode is non-atomic, that is, CouchDB will only + guarantee that some of the documents will be saved when you + send the request. The response will contain the list of + documents successfully inserted or updated during the + process. In the event of a crash, some of the documents may + have been successfully saved, and some will have been lost. + </para> + + <para> + In this mode, the response structure will indicate whether + the document was updated by supplying the new + <literal moreinfo="none">_rev</literal> parameter indicating a new document + revision was created. If the update failed, then you will + get an <literal moreinfo="none">error</literal> of type + <literal moreinfo="none">conflict</literal>. For example: + </para> + +<programlisting format="linespecific">[ + { + "id" : "FishStew", + "error" : "conflict", + "reason" : "Document update conflict." + }, + { + "id" : "LambStew", + "error" : "conflict", + "reason" : "Document update conflict." + }, + { + "id" : "7f7638c86173eb440b8890839ff35433", + "error" : "conflict", + "reason" : "Document update conflict." + } +]</programlisting> + + <para> + In this case no new revision has been created and you will + need to submit the document update, with the correct + revision tag, to update the document. + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">all-or-nothing</literal> + </para> + + <para> + In all-or-nothing mode, either all documents are written to + the database, or no documents are written to the database, + in the event of a system failure during commit. + </para> + + <para> + In addition, the per-document conflict checking is not + performed. Instead a new revision of the document is + created, even if the new revision is in conflict with the + current revision in the database. The returned structure + contains the list of documents with new revisions: + </para> + +<programlisting format="linespecific">[ + { + "id" : "FishStew", + "rev" : "2-e7af4c4e9981d960ecf78605d79b06d1" + }, + { + "id" : "LambStew", + "rev" : "2-0786321986194c92dd3b57dfbfc741ce" + }, + { + "id" : "7f7638c86173eb440b8890839ff35433", + "rev" : "2-bdd3bf3563bee516b96885a66c743f8e" + } +]</programlisting> + + <para> + When updating documents using this mode the revision of a + document included in views will be arbitrary. You can check + the conflict status for a document by using the + <literal moreinfo="none">conflicts=true</literal> query argument when + accessing the view. Conflicts should be handled individually + to ensure the consistency of your database. + </para> + + + + <para> + To use this mode, you must include the + <literal moreinfo="none">all_or_nothing</literal> field (set to true) within + the main body of the JSON of the request. + </para> + </listitem> + + </itemizedlist> + + <para> + The effects of different database operations on the different + modes are summarized in the table below: + </para> + + <table id="table-couchdb-api-db_db-bulk-docs_post-commit"> + <title>Conflicts on Bulk Inserts</title> + <tgroup cols="4"> + <thead> + <row> + <entry> + Transaction Mode + </entry> + <entry> + Transaction + </entry> + <entry> + Cause + </entry> + <entry> + Resolution + </entry> + </row> + </thead> + <tbody> + <row> + <entry> + Non-atomic + </entry> + <entry> + Insert + </entry> + <entry> + Requested document ID already exists + </entry> + <entry> + Resubmit with different document ID, or update the + existing document + </entry> + </row> + <row> + <entry> + Non-atomic + </entry> + <entry> + Update + </entry> + <entry> + Revision missing or incorrect + </entry> + <entry> + Resubmit with correct revision + </entry> + </row> + <row> + <entry> + All-or-nothing + </entry> + <entry> + Insert + </entry> + <entry> + Additional revision inserted + </entry> + <entry> + Resolve conflicted revisions + </entry> + </row> + <row> + <entry> + All-or-nothing + </entry> + <entry> + Update + </entry> + <entry> + Additional revision inserted + </entry> + <entry> + Resolve conflicted revisions + </entry> + </row> + </tbody> + </tgroup> + </table> + + <para> + Replication of documents is independent of the type of insert or + update. The documents and revisions created during a bulk insert + or update are replicated in the same way as any other document. + This can mean that if you make use of the all-or-nothing mode + the exact list of documents, revisions (and their conflict + state) may or may not be replicated to other databases + correctly. + </para> + + </section> + + <section id="couchdb-api-db_db-bulk-docs_post-errors"> + + <title>Bulk Document Validation and Conflict Errors</title> + + <para> + The JSON returned by the <literal moreinfo="none">_bulk_docs</literal> operation + consists of an array of JSON structures, one for each document + in the original submission. The returned JSON structure should + be examined to ensure that all of the documents submitted in the + original request were successfully added to the database. + </para> + + <para> + The exact structure of the returned information is shown in + <xref linkend="table-couchdb-api-db_db-bulk-docs-return-json"/>. + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-db_db-bulk-docs-return-json" class="jsonstructure"><title> + Bulk Document Response + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">docs</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + Bulk Docs Returned Documents + </entry></row><row><entry> <literal moreinfo="none">error</literal> </entry><entry> + Error type + </entry></row><row><entry> <literal moreinfo="none">id</literal> </entry><entry> + Document ID + </entry></row><row><entry> <literal moreinfo="none">reason</literal> </entry><entry> + Error string with extended reason + </entry></row></tbody></tgroup></table> + + <para> + When a document (or document revision) is not correctly comitted + to the database because of an error, you should check the + <literal moreinfo="none">error</literal> field to determine error type and + course of action. Errors will be one of the following type: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal moreinfo="none">conflict</literal> + </para> + + <para> + The document as submitted is in conflict. If you used the + default bulk transaction mode then the new revision will not + have been created and you will need to re-submit the + document to the database. If you used + <literal moreinfo="none">all-or-nothing</literal> mode then you will need to + manually resolve the conflicted revisions of the document. + </para> + + <para> + Conflict resolution of documents added using the bulk docs + interface is identical to the resolution procedures used + when resolving conflict errors during replication. + </para> + + + </listitem> + + <listitem> + <para> + <literal moreinfo="none">forbidden</literal> + </para> + + <para> + Entries with this error type indicate that the validation + routine applied to the document during submission has + returned an error. + </para> + + <para> + For example, if your validation routine includes the + following: + </para> + +<programlisting format="linespecific">throw({forbidden: 'invalid recipe ingredient'});</programlisting> + + <para> + The error returned will be: + </para> + +<programlisting format="linespecific">{ + "id" : "7f7638c86173eb440b8890839ff35433", + "error" : "forbidden", + "reason" : "invalid recipe ingredient" +}</programlisting> + + <para> + For more information, see + <xref linkend="couchdb-api-functional-validation"/>. + </para> + </listitem> + + </itemizedlist> + + </section> + + </section> + + <section id="couchdb-api-db_db-temp-view_post"> + + <title><literal moreinfo="none">POST /db/_temp_view</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_temp_view</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">POST /db/_temp_view</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON with the temporary view definition + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Temporary view result set + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">yes</entry></row></tbody></tgroup></informaltable> + + <para> + Creates (and executes) a temporary view based on the view function + supplied in the JSON request. For example: + </para> + +<programlisting format="linespecific">POST http://couchdb:5984/recipes/_temp_view +Content-Type: application/json + +{ + "map" : "function(doc) { if (doc.value > 9995) { emit(null, doc.value); } }" +}</programlisting> + + <para> + The resulting JSON response is the result from the execution of + the temporary view: + </para> + +<programlisting format="linespecific">{ + "total_rows" : 3, + "rows" : [ + { + "value" : 9998.41913029012, + "id" : "05361cc6aa42033878acc1bacb1f39c2", + "key" : null + }, + { + "value" : 9998.94149934853, + "id" : "1f443f471e5929dd7b252417625ed170", + "key" : null + }, + { + "value" : 9998.01511339154, + "id" : "1f443f471e5929dd7b252417629c102b", + "key" : null + } + ], + "offset" : 0 +}</programlisting> + + <para> + The arguments also available to standard view requests also apply + to temporary views, but the execution of the view may take some + time as it relies on being executed at the time of the request. In + addition to the time taken, they are also computationally very + expensive to produce. You should use a defined view if you want to + achieve the best performance. + </para> + + <para> + For more information, see + <xref linkend="couchdb-api-functional-views"/>. + </para> + + </section> + + <section id="couchdb-api-db_db-purge_post"> + + <title><literal moreinfo="none">POST /db/_purge</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_purge</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">POST /db/_purge</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the document IDs/revisions to be purged + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON structure with purged documents and purge sequence + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + A database purge permanently removes the references to deleted + documents from the database. Deleting a document within CouchDB + does not actually remove the documen from the database, instead, + the document is marked as a deleted (and a new revision is + created). This is to ensure that deleted documents are replicated + to other databases as having been deleted. This also means that + you can check the status of a document and identify that the + document has been deleted. + </para> + + <para> + The purge operation removes the refernces to the deleted documents + from the database. The purging of old documents is not replicated + to other databases. If you are replicating between databases and + have deleted a large number of documents you should run purge on + each database. + </para> + + <note> + <para> + Purging documents does not remove the space used by them on + disk. To reclaim disk space, you should run a database compact + (see <xref linkend="couchdb-api-db_db-compact_post"/>, and + compact views (see + <xref linkend="couchdb-api-db_db-compact-design-doc_post"/>). + </para> + </note> + + <para> + To perform a purge operation you must send a request including the + JSON of the document IDs that you want to purge. For example: + </para> + +<programlisting format="linespecific">POST http://couchdb:5984/recipes/_purge +Content-Type: application/json + +{ + "FishStew" : [ + "17-b3eb5ac6fbaef4428d712e66483dcb79" + ] +}</programlisting> + + <para> + The format of the request must include the document ID and one or + more revisions that must be purged. + </para> + + <para> + The response will contain the purge sequence number, and a list of + the document IDs and revisions successfully purged. + </para> + +<programlisting format="linespecific">{ + "purged" : { + "FishStew" : [ + "17-b3eb5ac6fbaef4428d712e66483dcb79" + ] + }, + "purge_seq" : 11 +}</programlisting> + + <section id="couchdb-api-db_db-purge_post-indexrebuild"> + + <title>Updating Indexes</title> + + <para> + The number of purges on a database is tracked using a purge + sequence. This is used by the view indexer to optimize the + updating of views that contain the purged documents. + </para> + + <para> + When the indexer identifies that the purge sequence on a + database has changed, it compares the purge sequence of the + database with that stored in the view index. If the difference + between the stored sequence and database is sequence is only 1, + then the indexer uses a cached list of the most recently purged + documents, and then removes these documents from the index + individually. This prevents completely rebuilding the index from + scratch. + </para> + + <para> + If the difference between the stored sequence number and current + database sequence is greater than 1, then the view index is + entirely rebuilt. This is an expensive operation as every + document in the database must be examined. + </para> + + </section> + + </section> + + <section id="couchdb-api-db_db-all-docs_get"> + + <title><literal moreinfo="none">GET /db/_all_docs</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_all_docs</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /db/_all_docs</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON object containing document information, ordered by the + document ID + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">descending</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return the documents in descending by key order + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">endkey</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Stop returning records when the specified key is reached + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">endkey_docid</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Stop returning records when the specified document ID is + reached + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">group</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Group the results using the reduce function to a group or + single row + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">group_level</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specify the group level to be used + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">include_docs</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Include the full content of the documents in the return + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">inclusive_end</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specifies whether the specified end key should be included + in the result + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>true</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">key</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return only documents that match the specified key + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">limit</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Limit the number of the returned documents to the specified + number + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">reduce</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Use the reduction function + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>true</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">skip</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Skip this number of records before starting to return the + results + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>0</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">stale</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Allow the results from a stale view to be used + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry/></row><row><entry/><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry/><entry><literal moreinfo="none">ok</literal></entry><entry>Allow stale views</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">startkey</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return records starting with the specified key + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">startkey_docid</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return records starting with the specified document ID + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">update_seq</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Include the update sequence in the generated results + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row></tbody></tgroup></informaltable> + + <para> + Returns a JSON structure of all of the documents in a given + database. The information is returned as a JSON structure + containing meta information about the return structure, and the + list documents and basic contents, consisting the ID, revision and + key. The key is generated from the document ID. + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-db_db-all-docs" class="jsonstructure"><title> + All Database Documents + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">offset</literal> </entry><entry> + Offset where the document list started + </entry></row><row><entry><literal moreinfo="none">rows</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + Array of document object + </entry></row><row><entry><literal moreinfo="none">total_rows</literal> </entry><entry> + Number of documents in the database/view + </entry></row><row><entry><literal moreinfo="none">update_seq</literal> (optional) </entry><entry> + Current update sequence for the database + </entry></row></tbody></tgroup></table> + + <para> + By default the information returned contains only the document ID + and revision. For example, the request: + </para> + +<programlisting role="httprequest" format="linespecific">GET http://couchdb:5984/recipes/_all_docs +Accept: application/json</programlisting> + + <para> + Returns the following structure: + </para> + +<programlisting role="httpresponse" format="linespecific">{ + "total_rows" : 18386, + "rows" : [ + { + "value" : { + "rev" : "1-bc0d5aed1e339b1cc1f29578f3220a45" + }, + "id" : "Aberffrawcake", + "key" : "Aberffrawcake" + }, + { + "value" : { + "rev" : "3-68a20c89a5e70357c20148f8e82ca331" + }, + "id" : "Adukiandorangecasserole-microwave", + "key" : "Adukiandorangecasserole-microwave" + }, + { + "value" : { + "rev" : "3-9b2851ed9b6f655cc4eb087808406c60" + }, + "id" : "Aioli-garlicmayonnaise", + "key" : "Aioli-garlicmayonnaise" + }, + ... + ], + "offset" : 0 +}</programlisting> + + <para> + The information is returned in the form of a temporary view of all + the database documents, with the returned key consisting of the ID + of the document. The remainder of the interface is therefore + identical to the View query arguments and their behavior. + </para> + + + + </section> + + <section id="couchdb-api-db_db-all-docs_post"> + + <title><literal moreinfo="none">POST /db/_all_docs</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_all_docs</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">POST /db/_all_docs</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the document IDs you want included + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the returned view + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + The <literal moreinfo="none">POST</literal> to <literal moreinfo="none">_all_docs</literal> allows + to specify multiple keys to be selected from the database. This + enables you to request multiple documents in a single request, in + place of multiple + <xref linkend="couchdb-api-dbdoc_db-doc_get"/> requests. + </para> + + <para> + The request body should contain a list of the keys to be returned + as an array to a <literal moreinfo="none">keys</literal> object. For example: + </para> + +<programlisting role="httprequest" format="linespecific">POST http://couchdb:5984/recipes/_all_docs +User-Agent: MyApp/0.1 libwww-perl/5.837 + +{ + "keys" : [ + "Zingylemontart", + "Yogurtraita" + ] +}</programlisting> + + <para> + The return JSON is the all documents structure, but with only the + selected keys in the output: + </para> + +<programlisting role="httpresponse" format="linespecific">{ + "total_rows" : 2666, + "rows" : [ + { + "value" : { + "rev" : "1-a3544d296de19e6f5b932ea77d886942" + }, + "id" : "Zingylemontart", + "key" : "Zingylemontart" + }, + { + "value" : { + "rev" : "1-91635098bfe7d40197a1b98d7ee085fc" + }, + "id" : "Yogurtraita", + "key" : "Yogurtraita" + } + ], + "offset" : 0 +}</programlisting> + + + + </section> + + <section id="couchdb-api-db_db-missing-revs_post"> + + <title><literal moreinfo="none">POST /db/_missing_revs</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_missing_revs</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">POST /db/_missing_revs</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON list of document revisions + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of missing revisions + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + </section> + + <section id="couchdb-api-db_db-revs-diff_post"> + + <title><literal moreinfo="none">POST /db/_revs_diff</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_revs_diff</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">POST /db/_revs_diff</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON list of document and revisions + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON list of differences from supplied document/revision list + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + </section> + + <section id="couchdb-api-db_db-security_get"> + + <title><literal moreinfo="none">GET /db/_security</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_security</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /db/_security</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the security object + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Gets the current secrity object from the specified database. The + security object consists of two compulsory elements, + <literal moreinfo="none">admins</literal> and <literal moreinfo="none">readers</literal>, which + are used to specify the list of users and/or roles that have admin + and reader rights to the database respectively. Any additional + fields in the security object are optional. The entire security + object is made available to validation and other internal + functions so that the database can control and limit + functionality. + </para> + + <para> + To get the existing security object you would send the following + request: + </para> + +<programlisting format="linespecific">{ + "admins" : { + "roles" : [], + "names" : [ + "mc", + "slp" + ] + }, + "readers" : { + "roles" : [], + "names" : [ + "tim", + "brian" + ] + } +}</programlisting> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-db-json-security" class="jsonstructure"><title> + Security Object + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">admins</literal> </entry><entry> + Roles/Users with admin privileges + </entry></row><row><entry> <literal moreinfo="none">roles</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + List of roles with parent privilege + </entry></row><row><entry> <literal moreinfo="none">users</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + List of users with parent privilege + </entry></row><row><entry><literal moreinfo="none">readers</literal> </entry><entry> + Roles/Users with reader privileges + </entry></row><row><entry> <literal moreinfo="none">roles</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + List of roles with parent privilege + </entry></row><row><entry> <literal moreinfo="none">users</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + List of users with parent privilege + </entry></row></tbody></tgroup></table> + + <note> + <para> + If the security object for a database has never beent set, then + the value returned will be empty. + </para> + </note> + + </section> + + <section id="couchdb-api-db_db-security_put"> + + <title><literal moreinfo="none">PUT /db/_security</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API PUT /db/_security</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">PUT /db/_security</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON specifying the admin and user security for the database + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON status message + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Sets the security object for the given database.For example, to + set the security object for the <literal moreinfo="none">recipes</literal> + database: + </para> + +<programlisting format="linespecific">PUT http://couchdb:5984/recipes/_security +Content-Type: application/json + +{ + "admins" : { + "roles" : [], + "names" : [ + "mc", + "slp" + ] + }, + "readers" : { + "roles" : [], + "names" : [ + "tim", + "brian" + ] + } +}</programlisting> + + <para> + If the setting was successful, a JSON status object will be + returned: + </para> + +<programlisting format="linespecific">{ + "ok" : true +}</programlisting> + + </section> + + <section id="couchdb-api-db_db-revs-limit_get"> + + <title><literal moreinfo="none">GET /db/_revs_limit</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_revs_limit</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /db/_revs_limit</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + The current revision limit setting + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Gets the current <literal moreinfo="none">revs_limit</literal> (revision limit) + setting. + </para> + + <para> + For example to get the current limit: + </para> + +<programlisting format="linespecific">GET http://couchdb:5984/recipes/_revs_limit +Content-Type: application/json</programlisting> + + <para> + The returned information is the current setting as a numerical + scalar: + </para> + +<programlisting format="linespecific">1000</programlisting> + + </section> + + <section id="couchdb-api-db_db-revs-limit_put"> + + <title><literal moreinfo="none">PUT /db/_revs_limit</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API PUT /db/_revs_limit</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">PUT /db/_revs_limit</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + A scalar integer of the revision limit setting + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Confirmation of setting of the revision limit + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Sets the maximum number of document revisions that will be tracked + by CouchDB, even after compaction has occurred. You can set the + revision limit on a database by using <literal moreinfo="none">PUT</literal> with + a scalar integer of the limit that you want to set as the request + body. + </para> + + <para> + For example to set the revs limit to 100 for the + <literal moreinfo="none">recipes</literal> database: + </para> + +<programlisting format="linespecific">PUT http://couchdb:5984/recipes/_revs_limit +Content-Type: application/json + +100</programlisting> + + <para> + If the setting was successful, a JSON status object will be + returned: + </para> + +<programlisting format="linespecific">{ + "ok" : true +}</programlisting> + + </section> + +</chapter> + + <chapter id="couchdb-api-dbdoc"> + + <title>CouchDB API Server Document Methods</title> + + <para> + The CouchDB API Server Document methods detail how to create, read, + update and delete documents within a database. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-dbdoc-summary"><title>Document API Calls</title><tgroup cols="3"><colspec colname="method"/><colspec colname="path"/><colspec colname="desc"/><thead><row><entry>Method</entry><entry>Path</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">POST</literal></entry><entry><literal moreinfo="none">/db</literal></entry><entry><link linkend="couchdb-api-dbdoc_db_post"> + Create a new document + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/db/doc</literal></entry><entry><link linkend="couchdb-api-dbdoc_db-doc_get"> + Returns the latest revision of the document + </link></entry></row><row><entry><literal moreinfo="none">HEAD</literal></entry><entry><literal moreinfo="none">/db/doc</literal></entry><entry><link linkend="couchdb-api-dbdoc_db-doc_head"> + Returns bare information in the HTTP Headers for the document + </link></entry></row><row><entry><literal moreinfo="none">PUT</literal></entry><entry><literal moreinfo="none">/db/doc</literal></entry><entry><link linkend="couchdb-api-dbdoc_db-doc_put"> + Inserts a new document, or new version of an existing document + </link></entry></row><row><entry><literal moreinfo="none">DELETE</literal></entry><entry><literal moreinfo="none">/db/doc</literal></entry><entry><link linkend="couchdb-api-dbdoc_db-doc_delete"> + Deletes the document + </link></entry></row><row><entry><literal moreinfo="none">COPY</literal></entry><entry><literal moreinfo="none">/db/doc</literal></entry><entry><link linkend="couchdb-api-dbdoc_db-doc_copy"> + Copies the document + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/db/doc/attachment</literal></entry><entry><link linkend="couchdb-api-dbdoc_db-doc-attachment_get"> + Gets the attachment of a document + </link></entry></row><row><entry><literal moreinfo="none">PUT</literal></entry><entry><literal moreinfo="none">/db/doc/attachment</literal></entry><entry><link linkend="couchdb-api-dbdoc_db-doc-attachment_put"> + Adds an attachment of a document + </link></entry></row><row><entry><literal moreinfo="none">DELETE</literal></entry><entry><literal moreinfo="none">/db/doc/attachment</literal></entry><entry><link linkend="couchdb-api-dbdoc_db-doc-attachment_delete"> + Deletes an attachment of a document + </link></entry></row></tbody></tgroup></table> + + <section id="couchdb-api-dbdoc_db_post"> + + <title><literal moreinfo="none">POST /db</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">POST /db</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the new document + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON with the committed document information + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">batch</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Allow document store request to be batched with others + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry/><entry><literal moreinfo="none">ok</literal></entry><entry>Enable</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>201</entry><entry namest="info" nameend="addinfo"> + Document has been created successfully + </entry></row><row><entry>409</entry><entry namest="info" nameend="addinfo"> + Conflict - a document with the specified document ID already + exists + </entry></row></tbody></tgroup></informaltable> + + <para> + Create a new document in the specified database, using the + supplied JSON document structure. If the JSON structure includes + the <literal moreinfo="none">_id</literal> field, then the document will be + created with the specified document ID. If the + <literal moreinfo="none">_id</literal> field is not specified, a new unique ID + will be generated. + </para> + + <para> + For example, you can generate a new document with a generated UUID + using the following request: + </para> + +<programlisting format="linespecific">POST http://couchdb:5984/recipes/ +Content-Type: application/json + +{ + "servings" : 4, + "subtitle" : "Delicious with fresh bread", + "title" : "Fish Stew" +}</programlisting> + + <para> + The return JSON will specify the automatically enerated ID and + revision information: + </para> + +<programlisting format="linespecific">{ + "id" : "64575eef70ab90a2b8d55fc09e00440d", + "ok" : true, + "rev" : "1-9c65296036141e575d32ba9c034dd3ee" +}</programlisting> + + <section id="couchdb-api-dbdoc_db_post-docid"> + + <title>Specifying the Document ID</title> + + <para> + The document ID can be specified by including the + <literal moreinfo="none">_id</literal> field in the JSON of the submitted + record. The following request will create the same document with + the ID <literal moreinfo="none">FishStew</literal>: + </para> + +<programlisting format="linespecific">POST http://couchdb:5984/recipes/ +Content-Type: application/json + +{ + "_id" : "FishStew", + "servings" : 4, + "subtitle" : "Delicious with fresh bread", + "title" : "Fish Stew" +}</programlisting> + + <para> + The structure of the submitted document is as shown in the table + below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-json-document" class="jsonstructure"><title> + CouchDB Document + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry><literal moreinfo="none">_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row></tbody></tgroup></table> + + <para> + In either case, the returned JSON will specify the document ID, + revision ID, and status message: + </para> + +<programlisting format="linespecific">{ + "id" : "FishStew", + "ok" : true, + "rev" : "1-9c65296036141e575d32ba9c034dd3ee" +}</programlisting> + + </section> + + <section id="couchdb-api-dbdoc_db_batchmode"> + + <title>Batch Mode Writes</title> + + <para> + You can write documents to the database at a higher rate by + using the batch option. This collects document writes together + in memory (on a user-by-user basis) before they are committed to + disk. This increases the risk of the documents not being stored + in the event of a failure, since the documents are not written + to disk immediately. + </para> + + <para> + To use the batched mode, append the <literal moreinfo="none">batch=ok</literal> + query argument to the URL of the <literal moreinfo="none">PUT</literal> or + <literal moreinfo="none">POST</literal> request. The CouchDB server will respond + with a 202 HTTP response code immediately. + </para> + + </section> + + <section id="couchdb-api-dbdoc_db-doc-attachments"> + + <title>Including Attachments</title> + + <para> + You can include one or more attachments with a given document by + incorporating the attachment information within the JSON of the + document. This provides a simpler alternative to loading + documents with attachments than making a separate call (see + <xref linkend="couchdb-api-dbdoc_db-doc-attachment_put"/>). + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-dbdoc-documentattachments" class="jsonstructure"><title> + Document with Attachments + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry><literal moreinfo="none">_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row><row><entry><literal moreinfo="none">_attachments</literal> (optional) </entry><entry> + Document Attachment + </entry></row><row><entry> <literal moreinfo="none">filename</literal> </entry><entry> + Attachment information + </entry></row><row><entry> <literal moreinfo="none">content_type</literal> </entry><entry> + MIME Content type string + </entry></row><row><entry> <literal moreinfo="none">data</literal> </entry><entry> + File attachment content, Base64 encoded + </entry></row></tbody></tgroup></table> + + <para> + The <literal moreinfo="none">filename</literal> will be the attachment name. For + example, when sending the JSON structure below: + </para> + +<programlisting format="linespecific">{ + "_id" : "FishStew", + "servings" : 4, + "subtitle" : "Delicious with fresh bread", + "title" : "Fish Stew" + "_attachments" : { + "styling.css" : { + "content-type" : "text/css", + "data" : "cCB7IGZvbnQtc2l6ZTogMTJwdDsgfQo=", + }, + }, +}</programlisting> + + <para> + The attachment <literal moreinfo="none">styling.css</literal> can be accessed + using <literal moreinfo="none">/recipes/FishStew/styling.css</literal>. For more + information on attachments, see + <xref linkend="couchdb-api-dbdoc_db-doc-attachment_get"/>. + </para> + + <para> + The document data embedded in to the structure must be encoded + using base64. + </para> + + </section> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_get"> + + <title><literal moreinfo="none">GET /db/doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /db/doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /db/doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Returns the JSON for the document + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">conflicts</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Returns the conflict tree for the document. + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry/><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry/><entry><literal moreinfo="none">true</literal></entry><entry>Includes the revisions</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">rev</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specify the revision to return + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry/><entry><literal moreinfo="none">true</literal></entry><entry>Includes the revisions</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">revs</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return a list of the revisions for the document + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">revs_info</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return a list of detailed revision information for the + document + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry/><entry><literal moreinfo="none">true</literal></entry><entry>Includes the revisions</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>201</entry><entry namest="info" nameend="addinfo"> + Document created + </entry></row><row><entry>400</entry><entry namest="info" nameend="addinfo"> + The format of the request or revision was invalid + </entry></row><row><entry>404</entry><entry namest="info" nameend="addinfo"> + The specified document or revision cannot be found, or has been + deleted + </entry></row><row><entry>409</entry><entry namest="info" nameend="addinfo"> + Conflict - a document with the specified document ID already + exists + </entry></row></tbody></tgroup></informaltable> + + <para> + Returns the specified <literal moreinfo="none">doc</literal> from the specified + <literal moreinfo="none">db</literal>. For example, to retrieve the document with + the id <literal moreinfo="none">FishStew</literal> you would send the following + request: + </para> + +<programlisting format="linespecific">GET http://couchdb:5984/recipes/FishStew +Content-Type: application/json +Accept: application/json</programlisting> + + <para> + The returned JSON is the JSON of the document, including the + document ID and revision number: + </para> + +<programlisting format="linespecific">{ + "_id" : "FishStew", + "_rev" : "3-a1a9b39ee3cc39181b796a69cb48521c", + "servings" : 4, + "subtitle" : "Delicious with a green salad", + "title" : "Irish Fish Stew" +}</programlisting> + + <para> + Unless you request a specific revision, the latest revision of the + document will always be returned. + </para> + + <section id="couchdb-api-dbdoc_db-doc_get-attachments"> + + <title>Attachments</title> + + <para> + If the document includes attachments, then the returned + structure will contain a summary of the attachments associatd + with the document, but not the attachment data itself. + </para> + + <para> + The JSON for the returned document will include the + <literal moreinfo="none">_attachments</literal> field, with one or more + attachment definitions. For example: + </para> + +<programlisting format="linespecific">{ + "_id" : "FishStew", + "servings" : 4, + "subtitle" : "Delicious with fresh bread", + "title" : "Fish Stew" + "_attachments" : { + "styling.css" : { + "stub" : true, + "content-type" : "text/css", + "length" : 783426, + }, + }, +}</programlisting> + + <para> + The format of the returned JSON is shown in the table below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-dbdoc-returneddocumentattachments" class="jsonstructure"><title> + Returned Document with Attachments + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry><literal moreinfo="none">_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row><row><entry><literal moreinfo="none">_attachments</literal> (optional) </entry><entry> + Document Attachment + </entry></row><row><entry> <literal moreinfo="none">filename</literal> </entry><entry> + Attachment + </entry></row><row><entry> <literal moreinfo="none">content_type</literal> </entry><entry> + MIME Content type string + </entry></row><row><entry> <literal moreinfo="none">length</literal> </entry><entry> + Length (bytes) of the attachment data + </entry></row><row><entry> <literal moreinfo="none">revpos</literal> </entry><entry> + Revision where this attachment exists + </entry></row><row><entry> <literal moreinfo="none">stub</literal> </entry><entry> + Indicates whether the attachment is a stub + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_get-revs"> + + <title>Getting a List of Revisions</title> + + <para> + You can obtain a list of the revisions for a given document by + adding the <literal moreinfo="none">revs=true</literal> parameter to the request + URL. For example: + </para> + +<programlisting format="linespecific">GET http://couchdb:5984/recipes/FishStew?revs=true +Accept: application/json</programlisting> + + <para> + The returned JSON structure includes the original document, + including a <literal moreinfo="none">_revisions</literal> structure that + includes the revision information: + </para> + +<programlisting format="linespecific">{ + "servings" : 4, + "subtitle" : "Delicious with a green salad", + "_id" : "FishStew", + "title" : "Irish Fish Stew", + "_revisions" : { + "ids" : [ + "a1a9b39ee3cc39181b796a69cb48521c", + "7c4740b4dcf26683e941d6641c00c39d", + "9c65296036141e575d32ba9c034dd3ee" + ], + "start" : 3 + }, + "_rev" : "3-a1a9b39ee3cc39181b796a69cb48521c" +}</programlisting> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-dbdoc-document_with_revs" class="jsonstructure"><title> + Returned CouchDB Document with Revision Info + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry><literal moreinfo="none">_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row><row><entry><literal moreinfo="none">_revisions</literal> </entry><entry> + CouchDB Document Revisions + </entry></row><row><entry> <literal moreinfo="none">ids</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + Array of valid revision IDs, in reverse order (latest first) + </entry></row><row><entry> <literal moreinfo="none">start</literal> </entry><entry> + Prefix number for the latest revision + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_get-revsextended"> + + <title>Obtaining an Extended Revision History</title> + + <para> + You can get additional information about the revisions for a + given document by supplying the <literal moreinfo="none">revs_info</literal> + argument to the query: + </para> + +<programlisting format="linespecific">GET http://couchdb:5984/recipes/FishStew?revs_info=true +Accept: application/json</programlisting> + + <para> + This returns extended revision information, including the + availability and status of each revision: + </para> + +<programlisting format="linespecific">{ + "servings" : 4, + "subtitle" : "Delicious with a green salad", + "_id" : "FishStew", + "_revs_info" : [ + { + "status" : "available", + "rev" : "3-a1a9b39ee3cc39181b796a69cb48521c" + }, + { + "status" : "available", + "rev" : "2-7c4740b4dcf26683e941d6641c00c39d" + }, + { + "status" : "available", + "rev" : "1-9c65296036141e575d32ba9c034dd3ee" + } + ], + "title" : "Irish Fish Stew", + "_rev" : "3-a1a9b39ee3cc39181b796a69cb48521c" +}</programlisting> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-dbdoc-document_with_revs_info" class="jsonstructure"><title> + Returned CouchDB Document with Detailed Revision Info + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry><literal moreinfo="none">_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row><row><entry><literal moreinfo="none">_revs_info</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + CouchDB Document Extended Revision Info + </entry></row><row><entry> <literal moreinfo="none">rev</literal> </entry><entry> + Full revision string + </entry></row><row><entry> <literal moreinfo="none">status</literal> </entry><entry> + Status of the revision + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_get-specrev"> + + <title>Obtaining a Specific Revision</title> + + <para> + To get a specific revision, use the <literal moreinfo="none">rev</literal> + argument to the request, and specify the full revision number: + </para> + +<programlisting format="linespecific">GET http://couchdb:5984/recipes/FishStew?rev=2-7c4740b4dcf26683e941d6641c00c39d +Accept: application/json</programlisting> + + <para> + The specified revision of the document will be returned, + including a <literal moreinfo="none">_rev</literal> field specifying the + revision that was requested: + </para> + +<programlisting format="linespecific">{ + "_id" : "FishStew", + "_rev" : "2-7c4740b4dcf26683e941d6641c00c39d", + "servings" : 4, + "subtitle" : "Delicious with a green salad", + "title" : "Fish Stew" +}</programlisting> + + </section> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_head"> + + <title><literal moreinfo="none">HEAD /db/doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API HEAD /db/doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">HEAD /db/doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">rev</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specify the revision to return + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">revs</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return a list of the revisions for the document + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">revs_info</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return a list of detailed revision information for the + document + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>404</entry><entry namest="info" nameend="addinfo"> + The specified document or revision cannot be found, or has been + deleted + </entry></row></tbody></tgroup></informaltable> + + <para> + Returns the HTTP Headers containing a minimal amount of + information about the specified document. The method supports the + same query arguments as the <literal moreinfo="none">GET</literal> method, but + only the header information (including document size, and the + revision as an ETag), is returned. For example, a simple + <literal moreinfo="none">HEAD</literal> request: + </para> + +<programlisting format="linespecific">HEAD http://couchdb:5984/recipes/FishStew +Content-Type: application/json</programlisting> + + <para> + Returns the following HTTP Headers: + </para> + +<programlisting format="linespecific">HTTP/1.1 200 OK +Server: CouchDB/1.0.1 (Erlang OTP/R13B) +Etag: "7-a19a1a5ecd946dad70e85233ba039ab2" +Date: Fri, 05 Nov 2010 14:54:43 GMT +Content-Type: text/plain;charset=utf-8 +Content-Length: 136 +Cache-Control: must-revalidate</programlisting> + + <para> + The <literal moreinfo="none">Etag</literal> header shows the current revision for + the requested document, and the <literal moreinfo="none">Content-Length</literal> + specifies the length of the data, if the document were requested + in full. + </para> + + <para> + Adding any of the query arguments (as supported by + <link linkend="couchdb-api-dbdoc_db-doc_get"><literal moreinfo="none">GET</literal></link> + method), then the resulting HTTP Headers will correspond to what + would be returned. Note that the current revision is not returned + when the <literal moreinfo="none">refs_info</literal> argument is used. For + example: + </para> + +<programlisting format="linespecific">HTTP/1.1 200 OK +Server: CouchDB/1.0.1 (Erlang OTP/R13B) +Date: Fri, 05 Nov 2010 14:57:16 GMT +Content-Type: text/plain;charset=utf-8 +Content-Length: 609 +Cache-Control: must-revalidate</programlisting> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_put"> + + <title><literal moreinfo="none">PUT /db/doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API PUT /db/doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">PUT /db/doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the new document, or updated version of the existed + document + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the document ID and revision + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">batch</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Allow document store request to be batched with others + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry/><entry><literal moreinfo="none">ok</literal></entry><entry>Enable</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal moreinfo="none">If-Match</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry>Current revision of the document for validation</entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry/><entry/></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>201</entry><entry namest="info" nameend="addinfo"> + Document has been created successfully + </entry></row><row><entry>202</entry><entry namest="info" nameend="addinfo"> + Document accepted for writing (batch mode) + </entry></row></tbody></tgroup></informaltable> + + <para> + The <literal moreinfo="none">PUT</literal> method creates a new named document, or + creates a new revision of the existing document. Unlike the + <link linkend="couchdb-api-dbdoc_db_post"><literal moreinfo="none">POST</literal></link> + method, you must specify the document ID in the request URL. + </para> + + <para> + For example, to create the docment <literal moreinfo="none">FishStew</literal>, + you would send the following request: + </para> + +<programlisting format="linespecific">PUT http://couchdb:5984/recipes/FishStew +Content-Type: application/json + +{ + "servings" : 4, + "subtitle" : "Delicious with fresh bread", + "title" : "Fish Stew" +}</programlisting> + + <para> + The return type is JSON of the status, document ID,and revision + number: + </para> + +<programlisting format="linespecific">{ + "id" : "FishStew", + "ok" : true, + "rev" : "1-9c65296036141e575d32ba9c034dd3ee" +}</programlisting> + + <section id="couchdb-api-dbdoc_db-doc_put-update"> + + <title>Updating an Existing Document</title> + + <para> + To update an existing document you must specify the current + revision number within the <literal moreinfo="none">_rev</literal> parameter. + For example: + </para> + +<programlisting format="linespecific">PUT http://couchdb:5984/recipes/FishStew +Content-Type: application/json + +{ + "_rev" : "1-9c65296036141e575d32ba9c034dd3ee", + "servings" : 4, + "subtitle" : "Delicious with fresh salad", + "title" : "Fish Stew" +}</programlisting> + + <para> + Alternatively, you can supply the current revision number in the + <literal moreinfo="none">If-Match</literal> HTTP header of the request. For + example: + </para> + +<programlisting format="linespecific">PUT http://couchdb:5984/recipes/FishStew +If-Match: 2-d953b18035b76f2a5b1d1d93f25d3aea +Content-Type: application/json + +{ + "servings" : 4, + "subtitle" : "Delicious with fresh salad", + "title" : "Fish Stew" +}</programlisting> + + <para> + The JSON returned will include the updated revision number: + </para> + +<programlisting format="linespecific">{ + "id" : "FishStew99", + "ok" : true, + "rev" : "2-d953b18035b76f2a5b1d1d93f25d3aea" +}</programlisting> + + <para> + For information on batched writes, which can provide improved + performance, see + <xref linkend="couchdb-api-dbdoc_db_batchmode"/>. + </para> + + </section> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_delete"> + + <title><literal moreinfo="none">DELETE /db/doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API DELETE /db/doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">DELETE /db/doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the deleted revision + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">rev</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Current revision of the document for validation + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal moreinfo="none">If-Match</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry>Current revision of the document for validation</entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry/><entry/></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>409</entry><entry namest="info" nameend="addinfo"> + Revision is missing, invalid or not the latest + </entry></row></tbody></tgroup></informaltable> + + <para> + Deletes the specified document from the database. You must supply + the current (latest) revision, either by using the + <literal moreinfo="none">rev</literal> parameter to specify the revision: + </para> + +<programlisting format="linespecific">DELETE http://couchdb:5984/recipes/FishStew?rev=3-a1a9b39ee3cc39181b796a69cb48521c +Content-Type: application/json</programlisting> + + <para> + Alternatively, you can use ETags with the + <literal moreinfo="none">If-Match</literal> field: + </para> + +<programlisting format="linespecific">DELETE http://couchdb:5984/recipes/FishStew +If-Match: 3-a1a9b39ee3cc39181b796a69cb48521c +Content-Type: application/json</programlisting> + + <para> + The returned JSON contains the document ID, revision and status: + </para> + +<programlisting format="linespecific">{ + "id" : "FishStew", + "ok" : true, + "rev" : "4-2719fd41187c60762ff584761b714cfb" +}</programlisting> + + <note> + <para> + Note that deletion of a record increments the revision number. + The use of a revision for deletion of the record allows + replication of the database to correctly track the deletion in + synchronized copies. + </para> + </note> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_copy"> + + <title><literal moreinfo="none">COPY /db/doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API COPY /db/doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">COPY /db/doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the new document and revision + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">rev</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Revision to copy from + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal moreinfo="none">Destination</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry>Destination document (and optional revision)</entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>no</entry></row><row><entry/><entry/><entry/></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>201</entry><entry namest="info" nameend="addinfo"> + Document has been copied and created successfully + </entry></row><row><entry>409</entry><entry namest="info" nameend="addinfo"> + Conflict (target document already exists) + </entry></row></tbody></tgroup></informaltable> + + <para> + The <literal moreinfo="none">COPY</literal> command (which is non-standard HTTP) + copies an existing document to a new or existing document. + </para> + + <para> + The source document is specified on the request line, with the + <literal moreinfo="none">Destination</literal> HTTP Header of the request + specifying the target document. + </para> + + <section id="couchdb-api-dbdoc_db-doc_copy-simple"> + + <title>Copying a Document</title> + + <para> + You can copy the latest version of a document to a new document + by specifying the current document and target document: + </para> + +<programlisting format="linespecific">COPY http://couchdb:5984/recipes/FishStew +Content-Type: application/json +Destination: IrishFishStew</programlisting> + + <para> + The above request copies the document + <literal moreinfo="none">FishStew</literal> to the new document + <literal moreinfo="none">IrishFishStew</literal>. The response is the ID and + revision of the new document. + </para> + +<programlisting format="linespecific">{ + "id" : "IrishFishStew", + "rev" : "1-9c65296036141e575d32ba9c034dd3ee" +}</programlisting> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_copy-specrev"> + + <title>Copying from a Specific Revision</title> + + <para> + To copy <emphasis>from</emphasis> a specific version, use the + <literal moreinfo="none">rev</literal> argument to the query string: + </para> + +<programlisting format="linespecific">COPY http://couchdb:5984/recipes/FishStew?rev=5-acfd32d233f07cea4b4f37daaacc0082 +Content-Type: application/json +Destination: IrishFishStew</programlisting> + + <para> + The new document will be created using the information in the + specified revision of the source document. + </para> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_copy-existing"> + + <title>Copying to an Existing Document</title> + + <para> + To copy to an existing document, you must specify the current + revision string for the target document, using the + <literal moreinfo="none">rev</literal> parameter to the + <literal moreinfo="none">Destination</literal> HTTP Header string. For example: + </para> + +<programlisting format="linespecific">COPY http://couchdb:5984/recipes/FishStew +Content-Type: application/json +Destination: IrishFishStew?rev=1-9c65296036141e575d32ba9c034dd3ee</programlisting> + + <para> + The return value will be the new revision of the copied + document: + </para> + +<programlisting format="linespecific">{ + "id" : "IrishFishStew", + "rev" : "2-55b6a1b251902a2c249b667dab1c6692" +}</programlisting> + + </section> + + </section> + + <section id="couchdb-api-dbdoc_db-doc-attachment_get"> + + <title><literal moreinfo="none">GET /db/doc/attachment</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /db/doc/attachment</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /db/doc/attachment</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Returns the document data + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Returns the file attachment <literal moreinfo="none">attachment</literal> + associated with the document <literal moreinfo="none">doc</literal>. The raw data + of the associated attachment is returned (just as if you were + accessing a static file. The returned HTTP + <literal moreinfo="none">Content-type</literal> will be the same as the content + type set when the document attachment was submitted into the + database. + </para> + + </section> + + <section id="couchdb-api-dbdoc_db-doc-attachment_put"> + + <title><literal moreinfo="none">PUT /db/doc/attachment</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API PUT /db/doc/attachment</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">PUT /db/doc/attachment</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + Raw document data + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON document status + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">rev</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Current document revision + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>no</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal moreinfo="none">Content-Length</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry>Length (bytes) of the attachment being uploaded</entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>no</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Header</emphasis></entry><entry><literal moreinfo="none">Content-Type</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry>MIME type for the uploaded attachment</entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>no</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Header</emphasis></entry><entry><literal moreinfo="none">If-Match</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry>Current revision of the document for validation</entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry/><entry/></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>201</entry><entry namest="info" nameend="addinfo"> + Attachment has been accepted + </entry></row></tbody></tgroup></informaltable> + + <para> + Upload the supplied content as an attachment to the specified + document (<literal moreinfo="none">doc</literal>). The + <literal moreinfo="none">attachment</literal> name provided must be a URL encoded + string. You must also supply either the <literal moreinfo="none">rev</literal> + query argument or the <literal moreinfo="none">If-Match</literal> HTTP header for + validation, and the HTTP headers (to set the attacment content + type). The content type is used when the attachment is requested + as the corresponding content-type in the returned document header. + </para> + + <para> + For example, you could upload a simple text document using the + following request: + </para> + +<programlisting format="linespecific">PUT http://couchdb:5984/recipes/FishStew/basic?rev=8-a94cb7e50ded1e06f943be5bfbddf8ca +Content-Length: 10 +Content-Type: text/plain + +Roast it</programlisting> + + <para> + Or by using the <literal moreinfo="none">If-Match</literal> HTTP header: + </para> + +<programlisting format="linespecific">PUT http://couchdb:5984/recipes/FishStew/basic +If-Match: 8-a94cb7e50ded1e06f943be5bfbddf8ca +Content-Length: 10 +Content-Type: text/plain + +Roast it</programlisting> + + <para> + The returned JSON contains the new document information: + </para> + +<programlisting format="linespecific">{ + "id" : "FishStew", + "ok" : true, + "rev" : "9-247bb19a41bfd9bfdaf5ee6e2e05be74" +}</programlisting> + + <note> + <para> + Uploading an attachment updates the corresponding document + revision. Revisions are tracked for the parent document, not + individual attachments. + </para> + </note> + + <section id="couchdb-api-dbdoc_db-doc-attachment_put-existing"> + + <title>Updating an Existing Attachment</title> + + <para> + Uploading an attachment using an existing attachment name will + update the corresponding stored content of the database. Since + you must supply the revision information to add an attachment to + a document, this serves as validation to update the existing + attachment. + </para> + + </section> + + </section> + + <section id="couchdb-api-dbdoc_db-doc-attachment_delete"> + + <title><literal moreinfo="none">DELETE /db/doc/attachment</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API DELETE /db/doc/attachment</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">DELETE /db/doc/attachment</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON status + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">rev</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Revision of the document to be deleted + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>no</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal moreinfo="none">If-Match</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry>Current revision of the document for validation</entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry/><entry/></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Attachment deleted successfully + </entry></row><row><entry>409</entry><entry namest="info" nameend="addinfo"> + Supplied revision is incorrect or missing + </entry></row></tbody></tgroup></informaltable> + + <para> + Deletes the attachment <literal moreinfo="none">attachment</literal> to the + specified <literal moreinfo="none">doc</literal>. You must supply the + <literal moreinfo="none">rev</literal> argument with the current revision to + delete the attachment. + </para> + + <para> + For example to delete the attachment <literal moreinfo="none">basic</literal> from + the recipe <literal moreinfo="none">FishStew</literal>: + </para> + +<programlisting format="linespecific">DELETE http://couchdb:5984/recipes/FishStew/basic?rev=9-247bb19a41bfd9bfdaf5ee6e2e05be74 +Content-Type: application/json</programlisting> + + <para> + The returned JSON contains the updated revision information: + </para> + +<programlisting format="linespecific">{ + "id" : "FishStew", + "ok" : true, + "rev" : "10-561bf6b1e27615cee83d1f48fa65dd3e" +}</programlisting> + + </section> + +</chapter> + + <chapter id="couchdb-api-localdb"> + + <title>CouchDB API Server Local (non-replicating) Document Methods</title> + + <para> + The Local (non-replicating) document interface allows you to create + local documents that are not replicated to other databases. These + documents can be used to hold configuration or other information + that is required specifically on the local CouchDB instance. + </para> + + <para> + Local documents have the following limitations: + </para> + + <itemizedlist> + + <listitem> + <para> + Local documents are not replicated to other databases. + </para> + </listitem> + + <listitem> + <para> + The ID of the local document must be known for the document to + accessed. You cannot obtain a list of local documents from the + database. + </para> + </listitem> + + <listitem> + <para> + Local documents are not output by views, or the + <literal moreinfo="none">_all_docs</literal> view. + </para> + </listitem> + + </itemizedlist> + + <para> + Local documents can be used when you want to store configuration or + other information for the curent (local) instance of a given + database. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-api-localdb-summary"><title>Local (non-replicating) Document API + Calls</title><tgroup cols="3"><colspec colname="method"/><colspec colname="path"/><colspec colname="desc"/><thead><row><entry>Method</entry><entry>Path</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/db/_local/local-doc</literal></entry><entry><link linkend="couchdb-api-localdb_db-local-localdoc_get"> + Returns the latest revision of the non-replicated document + </link></entry></row><row><entry><literal moreinfo="none">PUT</literal></entry><entry><literal moreinfo="none">/db/_local/local-doc</literal></entry><entry><link linkend="couchdb-api-localdb_db-local-localdoc_put"> + Inserts a new version of the non-replicated document + </link></entry></row><row><entry><literal moreinfo="none">DELETE</literal></entry><entry><literal moreinfo="none">/db/_local/local-doc</literal></entry><entry><link linkend="couchdb-api-localdb_db-local-localdoc_delete"> + Deletes the non-replicated document + </link></entry></row><row><entry><literal moreinfo="none">COPY</literal></entry><entry><literal moreinfo="none">/db/_local/local-doc</literal></entry><entry><link linkend="couchdb-api-localdb_db-local-localdoc_copy"> + Copies the non-replicated document + </link></entry></row></tbody></tgroup></table> + + <section id="couchdb-api-localdb_db-local-localdoc_get"> + + <title><literal moreinfo="none">GET /db/_local/local-doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_local/local-doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /db/_local/local-doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the returned document + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">rev</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specify the revision to return + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry/><entry><literal moreinfo="none">true</literal></entry><entry>Includes the revisions</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">revs</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return a list of the revisions for the document + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">revs_info</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return a list of detailed revision information for the + document + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry/><entry><literal moreinfo="none">true</literal></entry><entry>Includes the revisions</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>400</entry><entry namest="info" nameend="addinfo"> + The format of the request or revision was invalid + </entry></row><row><entry>404</entry><entry namest="info" nameend="addinfo"> + The specified document or revision cannot be found, or has been + deleted + </entry></row></tbody></tgroup></informaltable> + + <para> + Gets the specified local document. The semantics are identical to + accessing a standard document in the specified database, except + that the document is not replicated. See + <xref linkend="couchdb-api-dbdoc_db-doc_get"/>. + </para> + + </section> + + <section id="couchdb-api-localdb_db-local-localdoc_put"> + + <title><literal moreinfo="none">PUT /db/_local/local-doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API PUT /db/_local/local-doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">PUT /db/_local/local-doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the document + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON with the committed document information + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>201</entry><entry namest="info" nameend="addinfo"> + Document has been created successfully + </entry></row></tbody></tgroup></informaltable> + + <para> + Stores the specified local document. The semantics are identical + to storing a standard document in the specified database, except + that the document is not replicated. See + <xref linkend="couchdb-api-dbdoc_db-doc_put"/>. + </para> + + </section> + + <section id="couchdb-api-localdb_db-local-localdoc_delete"> + + <title><literal moreinfo="none">DELETE /db/_local/local-doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API DELETE /db/_local/local-doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">DELETE /db/_local/local-doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON with the deleted document information + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">rev</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Current revision of the document for validation + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal moreinfo="none">If-Match</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry>Current revision of the document for validation</entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry/><entry/></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>409</entry><entry namest="info" nameend="addinfo"> + Supplied revision is incorrect or missing + </entry></row></tbody></tgroup></informaltable> + + <para> + Deletes the specified local document. The semantics are identical + to deleting a standard document in the specified database, except + that the document is not replicated. See + <xref linkend="couchdb-api-dbdoc_db-doc_delete"/>. + </para> + + </section> + + <section id="couchdb-api-localdb_db-local-localdoc_copy"> + + <title><literal moreinfo="none">COPY /db/_local/local-doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API COPY /db/_local/local-doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">COPY /db/_local/local-doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the copied document + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">rev</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Revision to copy from + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal moreinfo="none">Destination</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry>Destination document (and optional revision)</entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>no</entry></row><row><entry/><entry/><entry/></row></tbody></tgroup></informaltable> + + <para> + Copies the specified local document. The semantics are identical + to copying a standard document in the specified database, except + that the document is not replicated. See + <xref linkend="couchdb-api-dbdoc_db-doc_copy"/>. + </para> + + </section> + +</chapter> + + <chapter id="couchdb-api-design"> + + <title>CouchDB API Server Design Document Methods</title> + + <para> + In CouchDB, design documents provide the main interface for building + a CouchDB application. The design document defines the views used to + extract information from CouchDB through one or more views. Design + documents are created within your CouchDB instance in the same way + as you create database documents, but the content and definition of + the documents is different. Design Documents are named using an ID + defined with the design document URL path, and this URL can then be + used to access the database contents. + </para> + + <para> + Views and lists operate together to provide automated (and + formatted) output from your database. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-design-summary"><title>Design Document API Calls</title><tgroup cols="3"><colspec colname="method"/><colspec colname="path"/><colspec colname="desc"/><thead><row><entry>Method</entry><entry>Path</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/db/_design/design-doc</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc_get"> + Returns the latest revision of the design document + </link></entry></row><row><entry><literal moreinfo="none">PUT</literal></entry><entry><literal moreinfo="none">/db/_design/design-doc</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc_put"> + Creates or updates a design document + </link></entry></row><row><entry><literal moreinfo="none">DELETE</literal></entry><entry><literal moreinfo="none">/db/_design/design-doc</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc_delete"> + Deletes the design document + </link></entry></row><row><entry><literal moreinfo="none">COPY</literal></entry><entry><literal moreinfo="none">/db/_design/design-doc</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc_copy"> + Copies the design document + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/db/_design/design-doc/_info</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-info_get"> + Returns information about the design document + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/db/_design/design-doc/_list/list-name/other-design-doc/view-name</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-list-listname-otherdesigndoc-viewname_get"> + Invokes the list handler to translate the given view results + </link></entry></row><row><entry><literal moreinfo="none">POST</literal></entry><entry><literal moreinfo="none">/db/_design/design-doc/_list/list-name/other-design-doc/view-name</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-list-listname-otherdesigndoc-viewname_post"> + Invokes the list handler to translate the given view results for + certain documents + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/db/_design/design-doc/_list/list-name/view-name</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-list-listname-viewname_get"> + Invokes the list handler to translate the given view results + </link></entry></row><row><entry><literal moreinfo="none">POST</literal></entry><entry><literal moreinfo="none">/db/_design/design-doc/_list/list-name/view-name</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-list-listname-viewname_post"> + Invokes the list handler to translate the given view results for + certain documents + </link></entry></row><row><entry><literal moreinfo="none">ALL</literal></entry><entry><literal moreinfo="none">/db/_design/design-doc/_rewrite/rewrite-name/anything</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-rewrite-rewritename-anything_all"> + Invokes the URL rewrite handler and processes the request after + rewriting + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/db/_design/design-doc/_show/show-name</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-show-showname_get"> + Invokes the show handler without a document + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/db/_design/design-doc/_show/show-name/doc</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-show-showname-doc_get"> + Invokes the show handler for the given document + </link></entry></row><row><entry><literal moreinfo="none">POST</literal></entry><entry><literal moreinfo="none">/db/_design/design-doc/_update/update-name</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-update-updatename_post"> + Invokes the update handler without a document ID + </link></entry></row><row><entry><literal moreinfo="none">PUT</literal></entry><entry><literal moreinfo="none">/db/_design/design-doc/_update/update-name/doc</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-update-updatename-doc_put"> + Invokes the update handler with a specific document ID + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/db/_design/design-doc/_view/view-name</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-view-viewname_get"> + Returns results of the view + </link></entry></row><row><entry><literal moreinfo="none">POST</literal></entry><entry><literal moreinfo="none">/db/_design/design-doc/_view/view-name</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-view-viewname_post"> + Returns certain rows from the view + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/db/_design/design-doc/attachment</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-attachment_get"> + Gets an attachment of the design document + </link></entry></row><row><entry><literal moreinfo="none">PUT</literal></entry><entry><literal moreinfo="none">/db/_design/design-doc/attachment</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-attachment_put"> + Inserts an attachment to the design document + </link></entry></row><row><entry><literal moreinfo="none">DELETE</literal></entry><entry><literal moreinfo="none">/db/_design/design-doc/attachment</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-attachment_delete"> + Deletes an attachment from the design document + </link></entry></row></tbody></tgroup></table> + + <section id="couchdb-api-design_db-design-designdoc_get"> + + <title><literal moreinfo="none">GET /db/_design/design-doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_design/design-doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /db/_design/design-doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the existing design document + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">rev</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specify the revision to return + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">revs</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return a list of the revisions for the document + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry/><entry><literal moreinfo="none">true</literal></entry><entry>Includes the revisions</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">revs_info</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return a list of detailed revision information for the + document + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry/><entry><literal moreinfo="none">true</literal></entry><entry>Includes the revisions</entry></row></tbody></tgroup></informaltable> + + <para> + Returns the specified design document, + <literal moreinfo="none">design-doc</literal> from the specified + <literal moreinfo="none">db</literal>. For example, to retrieve the design + document <literal moreinfo="none">recipes</literal> you would send the following + request: + </para> + +<programlisting format="linespecific">GET http://couchdb:5984/recipes/_design/recipes +Content-Type: application/json</programlisting> + + <para> + The returned string will be the JSON of the design document: + </para> + +<programlisting format="linespecific">{ + "_id" : "_design/recipes", + "_rev" : "5-39f56a392b86bbee57e2138921346406" + "language" : "javascript", + "views" : { + "by_recipe" : { + "map" : "function(doc) { if (doc.title != null) emit(doc.title, doc) }" + }, + }, +}</programlisting> + + <para> + A list of the revisions can be obtained by using the + <literal moreinfo="none">revs</literal> query argument, or an extended list of + revisions using the <literal moreinfo="none">revs_info</literal> query argument. + This operates in the same way as for other documents. Fur further + examples, see + <xref linkend="couchdb-api-dbdoc_db-doc_get"/>. + </para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc_put"> + + <title><literal moreinfo="none">PUT /db/_design/design-doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API PUT /db/_design/design-doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">PUT /db/_design/design-doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the design document + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON status + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Upload the specified design document, + <literal moreinfo="none">design-doc</literal>, to the specified database. The + design document should follow the definition of a design document, + as summarised in the following table. + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-json-designdoc" class="jsonstructure"><title> + Design Document + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">_id</literal> </entry><entry> + Design Document ID + </entry></row><row><entry><literal moreinfo="none">_rev</literal> </entry><entry> + Design Document Revision + </entry></row><row><entry><literal moreinfo="none">views</literal> </entry><entry> + View + </entry></row><row><entry> <literal moreinfo="none">viewname</literal> </entry><entry> + View Definition + </entry></row><row><entry> <literal moreinfo="none">map</literal> </entry><entry> + Map Function for View + </entry></row><row><entry> <literal moreinfo="none">reduce</literal> (optional) </entry><entry> + Reduce Function for View + </entry></row></tbody></tgroup></table> + + <para> + For more information on writing views, see + <xref linkend="couchdb-api-functional-views"/>. + </para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc_delete"> + + <title><literal moreinfo="none">DELETE /db/_design/design-doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API DELETE /db/_design/design-doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">DELETE /db/_design/design-doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of deleted design document + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">rev</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Current revision of the document for validation + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal moreinfo="none">If-Match</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry>Current revision of the document for validation</entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry/><entry/></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>409</entry><entry namest="info" nameend="addinfo"> + Supplied revision is incorrect or missing + </entry></row></tbody></tgroup></informaltable> + + <para> + Delete an existing design document. Deleting a design document + also deletes all of the associated view indexes, and recovers the + corresponding space on disk for the indexes in question. + </para> + + <para> + To delete, you must specify the current revision of the design + document using the <literal moreinfo="none">rev</literal> query argument. + </para> + + <para> + For example: + </para> + +<programlisting format="linespecific">DELETE http://couchdb:5984/recipes/_design/recipes?rev=2-ac58d589b37d01c00f45a4418c5a15a8 +Content-Type: application/json</programlisting> + + <para> + The response contains the delete document ID and revision: + </para> + +<programlisting format="linespecific">{ + "id" : "recipe/_design/recipes" + "ok" : true, + "rev" : "3-7a05370bff53186cb5d403f861aca154", +}</programlisting> + + </section> + + <section id="couchdb-api-design_db-design-designdoc_copy"> + + <title><literal moreinfo="none">COPY /db/_design/design-doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API COPY /db/_design/design-doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">COPY /db/_design/design-doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the copied document and revision + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">rev</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Revision to copy from + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal moreinfo="none">Destination</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry>Destination document (and optional revision)</entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>no</entry></row><row><entry/><entry/><entry/></row></tbody></tgroup></informaltable> + + <para> + The <literal moreinfo="none">COPY</literal> command (non-standard HTTP) copies an + existing design document to a new or existing document. + </para> + + <para> + The source design document is specified on the request line, with + the <literal moreinfo="none">Destination</literal> HTTP Header of the request + specifying the target document. + </para> + + <section id="couchdb-api-design_db-design-designdoc_copy-simple"> + + <title>Copying a Design Document</title> + + <para> + To copy the latest version of a design document to a new + document you specify the base document and target document: + </para> + +<programlisting format="linespecific">COPY http://couchdb:5984/recipes/_design/recipes +Content-Type: application/json +Destination: /recipes/_design/recipelist</programlisting> + + <para> + The above request copies the design document + <literal moreinfo="none">recipes</literal> to the new design document + <literal moreinfo="none">recipelist</literal>. The response is the ID and + revision of the new document. + </para> + +<programlisting format="linespecific">{ + "id" : "recipes/_design/recipelist" + "rev" : "1-9c65296036141e575d32ba9c034dd3ee", +}</programlisting> + + <note> + <para> + Copying a design document does automatically reconstruct the + view indexes. These will be recreated, as with other views, + the first time the new view is accessed. + </para> + </note> + + </section> + + <section id="couchdb-api-design_db-design-designdoc_copy-specrev"> + + <title>Copying from a Specific Revision</title> + + <para> + To copy <emphasis>from</emphasis> a specific version, use the + <literal moreinfo="none">rev</literal> argument to the query string: + </para> + +<programlisting format="linespecific">COPY http://couchdb:5984/recipes/_design/recipes?rev=1-e23b9e942c19e9fb10ff1fde2e50e0f5 +Content-Type: application/json +Destination: recipes/_design/recipelist</programlisting> + + <para> + The new design document will be created using the specified + revision of the source document. + </para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc_copy-existing"> + + <title>Copying to an Existing Design Document</title> + + <para> + To copy to an existing document, you must specify the current + revision string for the target document, using the + <literal moreinfo="none">rev</literal> parameter to the + <literal moreinfo="none">Destination</literal> HTTP Header string. For example: + </para> + +<programlisting format="linespecific">COPY http://couchdb:5984/recipes/_design/recipes +Content-Type: application/json +Destination: recipes/_design/recipelist?rev=1-9c65296036141e575d32ba9c034dd3ee</programlisting> + + <para> + The return value will be the new revision of the copied + document: + </para> + +<programlisting format="linespecific">{ + "id" : "recipes/_design/recipes" + "rev" : "2-55b6a1b251902a2c249b667dab1c6692", +}</programlisting> + + </section> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-attachment_get"> + + <title><literal moreinfo="none">GET /db/_design/design-doc/attachment</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_design/design-doc/attachment</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /db/_design/design-doc/attachment</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Document content + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Returns the file attachment <literal moreinfo="none">attachment</literal> + associated with the design document + <literal moreinfo="none">/_design_/design-doc</literal>. The raw data of the + associated attachment is returned (just as if you were accessing a + static file. The returned HTTP <literal moreinfo="none">Content-type</literal> + will be the same as the content type set when the document + attachment was submitted into the database. + </para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-attachment_put"> + + <title><literal moreinfo="none">PUT /db/_design/design-doc/attachment</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API PUT /db/_design/design-doc/attachment</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">PUT /db/_design/design-doc/attachment</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the design document + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON status statement + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">rev</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Current revision of the document for validation + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal moreinfo="none">If-Match</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry>Current revision of the document for validation</entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry/><entry/></row></tbody></tgroup></informaltable> + + <para> + Upload the supplied content as an attachment to the specified + design document (<literal moreinfo="none">/_design/design-doc</literal>). The + <literal moreinfo="none">attachment</literal> name provided must be a URL encoded + string. You must also supply either the <literal moreinfo="none">rev</literal> + query argument or the <literal moreinfo="none">If-Match</literal> HTTP header for + validation, and the HTTP headers (to set the attacment content + type). The content type is used when the attachment is requested + as the corresponding content-type in the returned document header. + </para> + + <para> + For example, you could upload a simple text document using the + following request: + </para> + +<programlisting format="linespecific">PUT http://couchdb:5984/recipes/_design/recipes/view.css?rev=7-f7114d4d81124b223283f3e89eee043e +Content-Length: 39 +Content-Type: text/plain + +div.recipetitle { +font-weight: bold; +}</programlisting> + + <para> + Or by using the <literal moreinfo="none">If-Match</literal> HTTP header: + </para> + +<programlisting format="linespecific">PUT http://couchdb:5984/recipes/FishStew/basic +If-Match: 7-f7114d4d81124b223283f3e89eee043e +Content-Length: 39 +Content-Type: text/plain + +div.recipetitle { +font-weight: bold; +}</programlisting> + + <para> + The returned JSON contains the new document information: + </para> + +<programlisting format="linespecific">{ + "id" : "_design/recipes" + "ok" : true, + "rev" : "8-cb2b7d94eeac76782a02396ba70dfbf5", +}</programlisting> + + <note> + <para> + Uploading an attachment updates the corresponding document + revision. Revisions are tracked for the parent document, not + individual attachments. + </para> + </note> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-attachment_delete"> + + <title><literal moreinfo="none">DELETE /db/_design/design-doc/attachment</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API DELETE /db/_design/design-doc/attachment</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">DELETE /db/_design/design-doc/attachment</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the deleted revision + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">rev</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Current revision of the document for validation + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal moreinfo="none">If-Match</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry>Current revision of the document for validation</entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry/><entry/></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>409</entry><entry namest="info" nameend="addinfo"> + Supplied revision is incorrect or missing + </entry></row></tbody></tgroup></informaltable> + + <para> + Deletes the attachment <literal moreinfo="none">attachment</literal> to the + specified <literal moreinfo="none">_design/design-doc</literal>. You must supply + the <literal moreinfo="none">rev</literal> argument with the current revision to + delete the attachment. + </para> + + <para> + For example to delete the attachment <literal moreinfo="none">view.css</literal> + from the design document <literal moreinfo="none">recipes</literal>: + </para> + +<programlisting format="linespecific">DELETE http://couchdb:5984/recipes/_design/recipes/view.css?rev=9-3db559f13a845c7751d407404cdeaa4a</programlisting> + + <para> + The returned JSON contains the updated revision information for + the parent document: + </para> + +<programlisting format="linespecific">{ + "id" : "_design/recipes" + "ok" : true, + "rev" : "10-f3b15bb408961f8dcc3d86c7d3b54c4c", +}</programlisting> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-info_get"> + + <title><literal moreinfo="none">GET /db/_design/design-doc/_info</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_design/design-doc/_info</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /db/_design/design-doc/_info</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the design document information + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Obtains information about a given design document, including the + index, index size and current status of the design document and + associated index information. + </para> + + <para> + For example, to get the information for the + <literal moreinfo="none">recipes</literal> design document: + </para> + +<programlisting format="linespecific">GET http://couchdb:5984/recipes/_design/recipes/_info +Content-Type: application/json</programlisting> + + <para> + This returns the following JSON structure: + </para> + +<programlisting format="linespecific">{ + "name" : "recipes" + "view_index" : { + "compact_running" : false, + "updater_running" : false, + "language" : "javascript", + "purge_seq" : 10, + "waiting_commit" : false, + "waiting_clients" : 0, + "signature" : "fc65594ee76087a3b8c726caf5b40687", + "update_seq" : 375031, + "disk_size" : 16491 + }, +}</programlisting> + + <para> + The individual fields in the returned JSON structure are detailed + in + <xref linkend="table-couchdb-api-design_db-designdoc-info-json"/>. + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-design_db-designdoc-info-json" class="jsonstructure"><title>Design Document Info JSON Contents</title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">name</literal> </entry><entry> + Name/ID of Design Document + </entry></row><row><entry><literal moreinfo="none">view_index</literal> </entry><entry> + View Index + </entry></row><row><entry> <literal moreinfo="none">compact_running</literal> </entry><entry> + Indicates whether a compaction routine is currently running on + the view + </entry></row><row><entry> <literal moreinfo="none">disk_size</literal> </entry><entry> + Size in bytes of the view as stored on disk + </entry></row><row><entry> <literal moreinfo="none">language</literal> </entry><entry> + Language for the defined views + </entry></row><row><entry> <literal moreinfo="none">purge_seq</literal> </entry><entry> + The purge sequence that has been processed + </entry></row><row><entry> <literal moreinfo="none">signature</literal> </entry><entry> + MD5 signature of the views for the design document + </entry></row><row><entry> <literal moreinfo="none">update_seq</literal> </entry><entry> + The update sequence of the corresponding database that has been + indexed + </entry></row><row><entry> <literal moreinfo="none">updater_running</literal> </entry><entry> + Indicates if the view is currently being updated + </entry></row><row><entry> <literal moreinfo="none">waiting_clients</literal> </entry><entry> + Number of clients waiting on views from this design document + </entry></row><row><entry> <literal moreinfo="none">waiting_commit</literal> </entry><entry> + Indicates if there are outstanding commits to the underlying + database that need to processed + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-view-viewname_get"> + + <title><literal moreinfo="none">GET /db/_design/design-doc/_view/view-name</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_design/design-doc/_view/view-name</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /db/_design/design-doc/_view/view-name</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the documents returned by the view + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">descending</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return the documents in descending by key order + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">endkey</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Stop returning records when the specified key is reached + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">endkey_docid</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Stop returning records when the specified document ID is + reached + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">group</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Group the results using the reduce function to a group or + single row + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">group_level</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specify the group level to be used + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">include_docs</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Include the full content of the documents in the return + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">inclusive_end</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specifies whether the specified end key should be included + in the result + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>true</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">key</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return only documents that match the specified key + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">limit</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Limit the number of the returned documents to the specified + number + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">reduce</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Use the reduction function + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>true</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">skip</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Skip this number of records before starting to return the + results + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>0</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">stale</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Allow the results from a stale view to be used + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry/></row><row><entry/><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry/><entry><literal moreinfo="none">ok</literal></entry><entry>Allow stale views</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">startkey</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return records starting with the specified key + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">startkey_docid</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return records starting with the specified document ID + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">update_seq</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Include the update sequence in the generated results + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row></tbody></tgroup></informaltable> + + <para> + Executes the specified <literal moreinfo="none">view-name</literal> from the + specified <literal moreinfo="none">design-doc</literal> design document. + </para> + + <section id="couchdb-api-design_db-design-designdoc-view-viewname_get-indexes"> + + <title>Querying Views and Indexes</title> + + <para> + The definition of a view within a design document also creates + an index based on the key information defined within each view. + The production and use of the index significantly increases the + speed of access and searching or selecting documents from the + view. + </para> + + <para> + However, the index is not updated when new documents are added + or modified in the database. Instead, the index is generated or + updated, either when the view is first accessed, or when the + view is accessed after a document has been updated. In each + case, the index is updated before the view query is executed + against the database. + </para> + + <para> + View indexes are updated incrementally in the following + situations: + </para> + + <itemizedlist> + + <listitem> + <para> + A new document has been added to the database. + </para> + </listitem> + + <listitem> + <para> + A document has been deleted from the database. + </para> + </listitem> + + <listitem> + <para> + A document in the database has been updated. + </para> + </listitem> + + </itemizedlist> + + <para> + View indexes are rebuilt entirely when the view definition + changes. To achieve this, a 'fingerprint' of the view definition + is created when the design document is updated. If the + fingerprint changes, then the view indexes are entirely rebuilt. + This ensures that changes to the view definitions are reflected + in the view indexes. + </para> + + <note> + <para> + View index rebuilds occur when one view from the same the view + group (i.e. all the views defined within a single a design + document) has been determined as needing a rebuild. For + example, if if you have a design document with different + views, and you update the database, all three view indexes + within the design document will be updated. + </para> + </note> + + <para> + Because the view is updated when it has been queried, it can + result in a delay in returned information when the view is + accessed, especially if there are a large number of documents in + the database and the view index does not exist. There are a + number of ways to mitigate, but not completely eliminate, these + issues. These include: + </para> + + <itemizedlist> + + <listitem> + <para> + Create the view definition (and associated design documents) + on your database before allowing insertion or updates to the + documents. If this is allowed while the view is being + accessed, the index can be updated incrementally. + </para> + </listitem> + + <listitem> + <para> + Manually force a view request from the database. You can do + this either before users are allowed to use the view, or you + can access the view manually after documents are added or + updated. + </para> + </listitem> + + <listitem> + <para> + Use the <literal moreinfo="none">/db/_changes</literal> method to monitor + for changes to the database and then access the view to + force the corresponding view index to be updated. See + <xref linkend="couchdb-api-db_db-changes_get"/> + for more information. + </para> + </listitem> + + <listitem> + <para> + Use a monitor with the + <literal moreinfo="none">update_notification</literal> section of the + CouchDB configuration file to monitor for changes to your + database, and trigger a view query to force the view to be + updated. For more information, see + <xref linkend="couchdb-single-configuration-update_notification"/>. + </para> + </listitem> + + </itemizedlist> + + <para> + None of these can completely eliminate the need for the indexes + to be rebuilt or updated when the view is accessed, but they may + lessen the effects on end-users of the index update affecting + the user experience. + </para> + + <para> + Another alternative is to allow users to access a 'stale' + version of the view index, rather than forcing the index to be + updated and displaying the updated results. Using a stale view + may not return the latest information, but will return the + results of the view query using an existing version of the + index. + </para> + + <para> + For example, to access the existing stale view + <literal moreinfo="none">by_recipe</literal> in the <literal moreinfo="none">recipes</literal> + design document: + </para> + +<programlisting format="linespecific">http://couchdb:5984/recipes/_design/recipes/_view/by_recipe?stale=ok</programlisting> + + <para> + Accessing a stale view: + </para> + + <itemizedlist> + + <listitem> + <para> + Does not trigger a rebuild of the view indexes, even if + there have been changes since the last access. + </para> + </listitem> + + <listitem> + <para> + Returns the current version of the view index, if a current + version exists. + </para> + </listitem> + + <listitem> + <para> + Returns an empty result set if the given view index does + exist. + </para> + </listitem> + + </itemizedlist> + + <para> + As an alternative, you use the <literal moreinfo="none">update_after</literal> + value to the <option>stale</option> paramater. This causes the + view to be returned as a stale view, but for the update process + to be triggered after the view information has been returned to + the client. + </para> + + <para> + In addition to using stale views, you can also make use of the + <literal moreinfo="none">update_seq</literal> query argument. Using this query + argument generates the view information including the update + sequence of the database from which the view was generated. The + returned value can be compared this to the current update + sequence exposed in the database information (returned by + <xref linkend="couchdb-api-db_db_get"/>). + </para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-view-viewname_get-sorting"> + + <title>Sorting Returned Rows</title> + + <para> + Each element within the returned array is sorted using native + UTF-8 sorting according to the contents of the key portion of + the emitted content. The basic order of output is as follows: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal moreinfo="none">null</literal> + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">false</literal> + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">true</literal> + </para> + </listitem> + + <listitem> + <para> + Numbers + </para> + </listitem> + + <listitem> + <para> + Text (case sensitive, lowercase first) + </para> + </listitem> + + <listitem> + <para> + Arrays (according to the values of each element, in order) + </para> + </listitem> + + <listitem> + <para> + Objects (according to the values of keys, in key order) + </para> + </listitem> + + </itemizedlist> + + + + <para> + You can reverse the order of the returned view information by + using the <literal moreinfo="none">descending</literal> query value set to true. + For example, Retrieving the list of recipes using the + <literal moreinfo="none">by_title</literal> (limited to 5 records) view: + </para> + +<programlisting format="linespecific">{ + "offset" : 0, + "rows" : [ + { + "id" : "3-tiersalmonspinachandavocadoterrine", + "key" : "3-tier salmon, spinach and avocado terrine", + "value" : [ + null, + "3-tier salmon, spinach and avocado terrine" + ] + }, + { + "id" : "Aberffrawcake", + "key" : "Aberffraw cake", + "value" : [ + null, + "Aberffraw cake" + ] + }, + { + "id" : "Adukiandorangecasserole-microwave", + "key" : "Aduki and orange casserole - microwave", + "value" : [ + null, + "Aduki and orange casserole - microwave" + ] + }, + { + "id" : "Aioli-garlicmayonnaise", + "key" : "Aioli - garlic mayonnaise", + "value" : [ + null, + "Aioli - garlic mayonnaise" + ] + }, + { + "id" : "Alabamapeanutchicken", + "key" : "Alabama peanut chicken", + "value" : [ + null, + "Alabama peanut chicken" + ] + } + ], + "total_rows" : 2667 +}</programlisting> + + <para> + Requesting the same in descending order will reverse the entire + view content. For example the request + </para> + +<programlisting format="linespecific">GET http://couchdb:5984/recipes/_design/recipes/_view/by_title?limit=5&descending=true +Accept: application/json +Content-Type: application/json</programlisting> + + <para> + Returns the last 5 records from the view: + </para> + +<programlisting format="linespecific">{ + "offset" : 0, + "rows" : [ + { + "id" : "Zucchiniinagrodolcesweet-sourcourgettes", + "key" : "Zucchini in agrodolce (sweet-sour courgettes)", + "value" : [ + null, + "Zucchini in agrodolce (sweet-sour courgettes)" + ] + }, + { + "id" : "Zingylemontart", + "key" : "Zingy lemon tart", + "value" : [ + null, + "Zingy lemon tart" + ] + }, + { + "id" : "Zestyseafoodavocado", + "key" : "Zesty seafood avocado", + "value" : [ + null, + "Zesty seafood avocado" + ] + }, + { + "id" : "Zabaglione", + "key" : "Zabaglione", + "value" : [ + null, + "Zabaglione" + ] + }, + { + "id" : "Yogurtraita", + "key" : "Yogurt raita", + "value" : [ + null, + "Yogurt raita" + ] + } + ], + "total_rows" : 2667 +}</programlisting> + + <para> + The sorting direction is applied before the filtering applied + using the <literal moreinfo="none">startkey</literal> and + <literal moreinfo="none">endkey</literal> query arguments. For example the + following query: + </para> + +<programlisting format="linespecific">GET http://couchdb:5984/recipes/_design/recipes/_view/by_ingredient?startkey=%22carrots%22&endkey=%22egg%22 +Accept: application/json +Content-Type: application/json</programlisting> + + <para> + Will operate correctly when listing all the matching entries + between <quote>carrots</quote> and <literal moreinfo="none">egg</literal>. If + the order of output is reversed with the + <literal moreinfo="none">descending</literal> query argument, the view request + will return no entries: + </para> + +<programlisting format="linespecific">GET http://couchdb:5984/recipes/_design/recipes/_view/by_ingredient?descending=true&startkey=%22carrots%22&endkey=%22egg%22 +Accept: application/json +Content-Type: application/json</programlisting> + + <para> + The returned result is empty: + </para> + +<programlisting format="linespecific">{ + "total_rows" : 26453, + "rows" : [], + "offset" : 21882 +}</programlisting> + + <para> + The results will be empty because the entries in the view are + reversed before the key filter is applied, and therefore the + <literal moreinfo="none">endkey</literal> of <quote>egg</quote> will be seen + before the <literal moreinfo="none">startkey</literal> of + <quote>carrots</quote>, resulting in an empty list. + </para> + + <para> + Instead, you should reverse the values supplied to the + <literal moreinfo="none">startkey</literal> and <literal moreinfo="none">endkey</literal> + parameters to match the descending sorting applied to the keys. + Changing the previous example to: + </para> + +<programlisting format="linespecific">GET http://couchdb:5984/recipes/_design/recipes/_view/by_ingredient?descending=true&startkey=%22egg%22&endkey=%22carrots%22 +Accept: application/json +Content-Type: application/json</programlisting> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-view-viewname_get-ranges"> + + <title>Specifying Start and End Values</title> + + <para> + The <literal moreinfo="none">startkey</literal> and <literal moreinfo="none">endkey</literal> + query arguments can be used to specify the range of values to be + displayed when querying the view. + </para> + + <note> + <para> + The values + </para> + </note> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-view-viewname_get-limit"> + + <title>Using Limits and Skipping Rows</title> + + <para> + TBC + </para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-view-viewname_get-reduction"> + + <title>View Reduction and Grouping</title> + + <para> + TBC + </para> + + </section> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-view-viewname_post"> + + <title><literal moreinfo="none">POST /db/_design/design-doc/_view/view-name</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_design/design-doc/_view/view-name</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">POST /db/_design/design-doc/_view/view-name</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + List of keys to be returned from specified view + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the documents returned by the view + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">descending</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return the documents in descending by key order + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">endkey</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Stop returning records when the specified key is reached + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">endkey_docid</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Stop returning records when the specified document ID is + reached + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">group</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Group the results using the reduce function to a group or + single row + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">group_level</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specify the group level to be used + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">include_docs</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Include the full content of the documents in the return + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">inclusive_end</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specifies whether the specified end key should be included + in the result + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>true</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">key</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return only documents that match the specified key + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">limit</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Limit the number of the returned documents to the specified + number + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">reduce</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Use the reduction function + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>true</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">skip</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Skip this number of records before starting to return the + results + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>0</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">stale</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Allow the results from a stale view to be used + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry/></row><row><entry/><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry/><entry><literal moreinfo="none">ok</literal></entry><entry>Allow stale views</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">startkey</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return records starting with the specified key + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">startkey_docid</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return records starting with the specified document ID + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">update_seq</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Include the update sequence in the generated results + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row></tbody></tgroup></informaltable> + + <para> + Executes the specified <literal moreinfo="none">view-name</literal> from the + specified <literal moreinfo="none">design-doc</literal> design document. Unlike + the <literal moreinfo="none">GET</literal> method for accessing views, the + <literal moreinfo="none">POST</literal> method supports the specification of + explicit keys to be retrieved from the view results. The remainder + of the <literal moreinfo="none">POST</literal> view functionality is identical to + the + <xref linkend="couchdb-api-design_db-design-designdoc-view-viewname_get"/> + fun + </para> + + <para> + For example, the request below will return all the recipes where + the key for the view matches either <quote>claret</quote> or + <quote>clear apple cider</quote> : + </para> + +<programlisting format="linespecific">POST http://couchdb:5984/recipes/_design/recipes/_view/by_ingredient +Content-Type: application/json + +{ + "keys" : [ + "claret", + "clear apple juice" + ] +}</programlisting> + + <para> + The returned view data contains the standard view information, but + only where the keys match. + </para> + +<programlisting format="linespecific">{ + "total_rows" : 26484, + "rows" : [ + { + "value" : [ + "Scotch collops" + ], + "id" : "Scotchcollops", + "key" : "claret" + }, + { + "value" : [ + "Stand pie" + ], + "id" : "Standpie", + "key" : "clear apple juice" + } + ], + "offset" : 6324 +}</programlisting> + + <section id="couchdb-api-design_db-design-designdoc-view-viewname_post-multidoc"> + + <title>Multi-document Fetching</title> + + <para> + By combining the <literal moreinfo="none">POST</literal> method to a given view + with the <literal moreinfo="none">include_docs=true</literal> query argument you + can obtain multiple documents from a database. The result is + more efficient than using multiple + <xref linkend="couchdb-api-dbdoc_db-doc_get"/> + requests. + </para> + + <para> + For example, sending the following request for ingredients + matching <quote>claret</quote> and <quote>clear apple + juice</quote>: + </para> + +<programlisting format="linespecific">POST http://couchdb:5984/recipes/_design/recipes/_view/by_ingredient?include_docs=true +Content-Type: application/json + +{ + "keys" : [ + "claret", + "clear apple juice" + ] +}</programlisting> + + <para> + Returns the full document for each recipe: + </para> + +<programlisting format="linespecific">{ + "offset" : 6324, + "rows" : [ + { + "doc" : { + "_id" : "Scotchcollops", + "_rev" : "1-bcbdf724f8544c89697a1cbc4b9f0178", + "cooktime" : "8", + "ingredients" : [ + { + "ingredient" : "onion", + "ingredtext" : "onion, peeled and chopped", + "meastext" : "1" + }, + ... + ], + "keywords" : [ + "cook method.hob, oven, grill@hob", + "diet@wheat-free", + "diet@peanut-free", + "special collections@classic recipe", + "cuisine@british traditional", + "diet@corn-free", + "diet@citrus-free", + "special collections@very easy", + "diet@shellfish-free", + "main ingredient@meat", + "occasion@christmas", + "meal type@main", + "diet@egg-free", + "diet@gluten-free" + ], + "preptime" : "10", + "servings" : "4", + "subtitle" : "This recipe comes from an old recipe book of 1683 called 'The Gentlewoman's Kitchen'. This is an excellent way of making a rich and full-flavoured meat dish in a very short time.", + "title" : "Scotch collops", + "totaltime" : "18" + }, + "id" : "Scotchcollops", + "key" : "claret", + "value" : [ + "Scotch collops" + ] + }, + { + "doc" : { + "_id" : "Standpie", + "_rev" : "1-bff6edf3ca2474a243023f2dad432a5a", + "cooktime" : "92", + "ingredients" : [ +... ], + "keywords" : [ + "diet@dairy-free", + "diet@peanut-free", + "special collections@classic recipe", + "cuisine@british traditional", + "diet@corn-free", + "diet@citrus-free", + "occasion@buffet party", + "diet@shellfish-free", + "occasion@picnic", + "special collections@lunchbox", + "main ingredient@meat", + "convenience@serve with salad for complete meal", + "meal type@main", + "cook method.hob, oven, grill@hob / oven", + "diet@cow dairy-free" + ], + "preptime" : "30", + "servings" : "6", + "subtitle" : "Serve this pie with pickled vegetables and potato salad.", + "title" : "Stand pie", + "totaltime" : "437" + }, + "id" : "Standpie", + "key" : "clear apple juice", + "value" : [ + "Stand pie" + ] + } + ], + "total_rows" : 26484 +}</programlisting> + + </section> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-show-showname_get"> + + <title><literal moreinfo="none">POST /db/_design/design-doc/_show/show-name</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_design/design-doc/_show/show-name</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /db/_design/design-doc/_show/show-name</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Returns the result of the show + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">details</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Indicates whether details should be included + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">format</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Format of the returned information + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row></tbody></tgroup></informaltable> + + <para/> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-show-showname-doc_get"> + + <title><literal moreinfo="none">POST /db/_design/design-doc/_show/show-name/doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_design/design-doc/_show/show-name/doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /db/_design/design-doc/_show/show-name/doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Returns the show for the given document + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para/> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-list-listname-otherdesigndoc-viewname_get"> + + <title><literal moreinfo="none">GET + /db/_design/design-doc/_list/list-name/other-design-doc/view-name</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_design/design-doc/_list/list-name/other-design-doc/view-name</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /db/_design/design-doc/_list/list-name/other-design-doc/view-name</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + TBC + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + TBC + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-list-listname-otherdesigndoc-viewname_post"> + + <title><literal moreinfo="none">POST + /db/_design/design-doc/_list/list-name/other-design-doc/view-name</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_design/design-doc/_list/list-name/other-design-doc/view-name</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">POST /db/_design/design-doc/_list/list-name/other-design-doc/view-name</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + TBC + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + TBC + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-list-listname-viewname_get"> + + <title><literal moreinfo="none">GET /db/_design/design-doc/_list/list-name/view-name</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_design/design-doc/_list/list-name/view-name</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /db/_design/design-doc/_list/list-name/view-name</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + TBC + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + TBC + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-list-listname-viewname_post"> + + <title><literal moreinfo="none">POST /db/_design/design-doc/_list/list-name/view-name</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_design/design-doc/_list/list-name/view-name</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">POST /db/_design/design-doc/_list/list-name/view-name</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + TBC + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + TBC + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-update-updatename-doc_put"> + + <title><literal moreinfo="none">PUT /db/_design/design-doc/_update/updatename/doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API PUT /db/_design/design-doc/_update/update-name/doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">PUT /db/_design/design-doc/_update/update-name/doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + Document update information + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Updated document + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-update-updatename_post"> + + <title><literal moreinfo="none">POST /db/_design/design-doc/_update/updatename</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_design/design-doc/_update/update-name</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">POST /db/_design/design-doc/_update/update-name</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + Document update information + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Updated document + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-rewrite-rewritename-anything"> + + <title><literal moreinfo="none">ALL + /db/_design/design-doc/_rewrite/rewrite-name/anything</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API ALL /db/_design/design-doc/_rewrite/rewrite-name/anything</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">ALL /db/_design/design-doc/_rewrite/rewrite-name/anything</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + TBC + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + TBC + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + </section> + +</chapter> + + <chapter id="couchdb-api-misc"> + + <title>CouchDB API Server Miscellaneous Methods</title> + + <para> + The CouchDB Miscellaneous interface provides the basic interface to + a CouchDB server for obtaining CouchDB information and getting and + setting configuration information. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-misc-summary"><title>Miscellaneous API Calls</title><tgroup cols="3"><colspec colname="method"/><colspec colname="path"/><colspec colname="desc"/><thead><row><entry>Method</entry><entry>Path</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/</literal></entry><entry><link linkend="couchdb-api-misc_root_get"> + Get the welcome message and version information + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/_active_tasks</literal></entry><entry><link linkend="couchdb-api-misc_active-tasks_get"> + Obtain a list of the tasks running in the server + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/_all_dbs</literal></entry><entry><link linkend="couchdb-api-misc_all-dbs_get"> + Get a list of all the DBs + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/_log</literal></entry><entry><link linkend="couchdb-api-misc_log_get"> + Return the server log file + </link></entry></row><row><entry><literal moreinfo="none">POST</literal></entry><entry><literal moreinfo="none">/_replicate</literal></entry><entry><link linkend="couchdb-api-misc_replicate_post"> + Set or cancel replication + </link></entry></row><row><entry><literal moreinfo="none">POST</literal></entry><entry><literal moreinfo="none">/_restart</literal></entry><entry><link linkend="couchdb-api-misc_restart_post"> + Restart the server + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/_stats</literal></entry><entry><link linkend="couchdb-api-misc_stats_get"> + Return server statistics + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/_utils</literal></entry><entry><link linkend="couchdb-api-misc_utils_get"> + CouchDB administration interface (Futon) + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/_uuids</literal></entry><entry><link linkend="couchdb-api-misc_uuids_get"> + Get generated UUIDs from the server + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/favicon.ico</literal></entry><entry><link linkend="couchdb-api-misc_favicon_get"> + Get the site icon + </link></entry></row></tbody></tgroup></table> + + <section id="couchdb-api-misc_root_get"> + + <title><literal moreinfo="none">GET /</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Welcome message and version + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Request completed successfully. + </entry></row></tbody></tgroup></informaltable> + + <para> + Accessing the root of a CouchDB instance returns meta information + about the instance. The response is a JSON structure containing + information about the server, including a welcome message and the + version of the server. + </para> + +<programlisting format="linespecific">{ + "couchdb" : "Welcome", + "version" : "1.0.1" +}</programlisting> + + </section> + + <section id="couchdb-api-misc_active-tasks_get"> + + <title><literal moreinfo="none">GET /_active_tasks</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /_active_tasks</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /_active_tasks</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + List of running tasks, including the task type, name, status and + process ID + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Request completed successfully. + </entry></row></tbody></tgroup></informaltable> + + <para> + You can obtain a list of active tasks by using the + <literal moreinfo="none">/_active_tasks</literal> URL. The result is a JSON array + of the currently running tasks, with each task being described + with a single object. For example: + </para> + +<programlisting format="linespecific">[ + { + "pid" : "<0.11599.0>", + "status" : "Copied 0 of 18369 changes (0%)", + "task" : "recipes", + "type" : "Database Compaction" + } +]</programlisting> + + <para> + The returned structure includes the following fields for each + task: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-misc-active-tasks-json" class="jsonstructure"><title> + List of Active Tasks + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">tasks</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + Active Task + </entry></row><row><entry> <literal moreinfo="none">pid</literal> </entry><entry> + Process ID + </entry></row><row><entry> <literal moreinfo="none">status</literal> </entry><entry> + Task status message + </entry></row><row><entry> <literal moreinfo="none">task</literal> </entry><entry> + Task name + </entry></row><row><entry> <literal moreinfo="none">type</literal> </entry><entry> + Operation Type + </entry></row></tbody></tgroup></table> + + <para> + For operation type, valid values include: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal moreinfo="none">Database Compaction</literal> + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">Replication</literal> + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">View Group Compaction</literal> + </para> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">View Group Indexer</literal> + </para> + </listitem> + + </itemizedlist> + + </section> + + <section id="couchdb-api-misc_all-dbs_get"> + + <title><literal moreinfo="none">GET /_all_dbs</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /_all_dbs</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /_all_dbs</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON list of DBs + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Request completed successfully. + </entry></row></tbody></tgroup></informaltable> + + <para> + Returns a list of all the databases in the CouchDB instance. For + example: + </para> + +<programlisting format="linespecific">GET http://couchdb:5984/_all_dbs +Accept: application/json</programlisting> + + <para> + The return is a JSON array: + </para> + +<programlisting format="linespecific">[ + "_users", + "contacts", + "docs", + "invoices", + "locations" +]</programlisting> + + </section> + + <section id="couchdb-api-misc_log_get"> + + <title><literal moreinfo="none">GET /_log</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /_log</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /_log</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Log content + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">bytes</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Bytes to be returned + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>1000</entry></row><row><entry/><entry/><entry/></row><row><entry/><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">offset</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Offset in bytes where the log tail should be started + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry/><entry><emphasis role="bold">Default</emphasis></entry><entry>0</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Request completed successfully. + </entry></row></tbody></tgroup></informaltable> + + <para> + Gets the CouchDB log, equivalent to accessing the local log file + of the corresponding CouchDB instance. + </para> + + <para> + When you request the log, the response is returned as plain + (UTF-8) text, with an HTTP <literal moreinfo="none">Content-type</literal> header + as <literal moreinfo="none">text/plain</literal>. + </para> + + <para> + For example, the request: + </para> + +<programlisting format="linespecific">GET http://couchdb:5984/_log +Accept: */*</programlisting> + + <para> + The raw text is returned: + </para> + +<programlisting format="linespecific">[Wed, 27 Oct 2010 10:49:42 GMT] [info] [<0.23338.2>] 192.168.0.2 - - 'PUT' /authdb 401 + +[Wed, 27 Oct 2010 11:02:19 GMT] [info] [<0.23428.2>] 192.168.0.116 - - 'GET' /recipes/FishStew 200 + +[Wed, 27 Oct 2010 11:02:19 GMT] [info] [<0.23428.2>] 192.168.0.116 - - 'GET' /_session 200 + +[Wed, 27 Oct 2010 11:02:19 GMT] [info] [<0.24199.2>] 192.168.0.116 - - 'GET' / 200 + +[Wed, 27 Oct 2010 13:03:38 GMT] [info] [<0.24207.2>] 192.168.0.116 - - 'GET' /_log?offset=5 200</programlisting> + + <para> + If you want to pick out specific parts of the log information you + can use the <literal moreinfo="none">bytes</literal> argument, which specifies the + number of bytes to be returned, and <literal moreinfo="none">offset</literal>, + which specifies where the reading of the log should start, counted + back from the end. For example, if you use the following request: + </para> + +<programlisting format="linespecific">GET /_log?bytes=500&offset=2000</programlisting> + + <para> + Reading of the log will start at 2000 bytes from the end of the + log, and 500 bytes will be shown. + </para> + + </section> + + <section id="couchdb-api-misc_replicate_post"> + + <title><literal moreinfo="none">POST /_replicate</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /_replicate</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">POST /_replicate</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + Replication specification + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Welcome message and version + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Replication request successfully completed + </entry></row><row><entry>202</entry><entry namest="info" nameend="addinfo"> + Continuous replication request has been accepted + </entry></row><row><entry>404</entry><entry namest="info" nameend="addinfo"> + Either the source or target DB is not found + </entry></row><row><entry>500</entry><entry namest="info" nameend="addinfo"> + JSON specification was invalid + </entry></row></tbody></tgroup></informaltable> + + <para> + Request, configure, or stop, a replication operation. + </para> + + <para> + The specification of the replication request is controlled through + the JSON content of the request. The JSON should be an object with + the fields defining the source, target and other options. The + fields of the JSON request are shown in the table below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-misc-json-replication" class="jsonstructure"><title> + Replication Settings + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">cancel</literal> (optional) </entry><entry> + Cancels the replication + </entry></row><row><entry><literal moreinfo="none">continuous</literal> (optional) </entry><entry> + Configure the replication to be continuous + </entry></row><row><entry><literal moreinfo="none">create_target</literal> (optional) </entry><entry> + Creates the target database + </entry></row><row><entry><literal moreinfo="none">doc_ids</literal> (optional) </entry><entry> + Array of document IDs to be synchronized + </entry></row><row><entry><literal moreinfo="none">proxy</literal> (optional) </entry><entry> + Address of a proxy server through which replication should occur + </entry></row><row><entry><literal moreinfo="none">source</literal> </entry><entry> + Source database name or URL + </entry></row><row><entry><literal moreinfo="none">target</literal> </entry><entry> + Target database name or URL + </entry></row></tbody></tgroup></table> + + <section id="couchdb-api-misc_replicate_post-operation"> + + <title>Replication Operation</title> + + <para> + The aim of the replication is that at the end of the process, + all active documents on the source database are also in the + destination database and all documents that were deleted in the + source databases are also deleted (if they exist) on the + destination database. + </para> + + <para> + Replication can be described as either push or pull replication: + </para> + + <itemizedlist> + + <listitem> + <para> + <emphasis>Pull replication</emphasis> is where the + <literal moreinfo="none">source</literal> is the remote CouchDB instance, + and the <literal moreinfo="none">destination</literal> is the local + database. + </para> + + <para> + Pull replication is the most useful solution to use if your + source database has a permanent IP address, and your + destination (local) database may have a dynamically assigned + IP address (for example, through DHCP). This is particularly + important if you are replicating to a mobile or other device + from a central server. + </para> + </listitem> + + <listitem> + <para> + <emphasis>Push replication</emphasis> is where the + <literal moreinfo="none">source</literal> is a local database, and + <literal moreinfo="none">destination</literal> is a remote database. + </para> + </listitem> + + </itemizedlist> + + </section> + + <section id="couchdb-api-misc_replicate_post-sourcetarget"> + + <title>Specifying the Source and Target Database</title> + + <para> + You must use the URL specification of the CouchDB database if + you want to perform replication in either of the following two + situations: + </para> + + <itemizedlist> + + <listitem> + <para> + Replication with a remote database (i.e. another instance of + CouchDB on the same host, or a different host) + </para> + </listitem> + + <listitem> + <para> + Replication with a database that requires authentication + </para> + </listitem> + + </itemizedlist> + + <para> + For example, to request replication between a database local to + the CouchDB instance to which you send the request, and a remote + database you might use the following request: + </para> + +<programlisting format="linespecific">POST http://couchdb:5984/_replicate +Content-Type: application/json +Accept: application/json + +{ + "source" : "recipes", + "target" : "http://coucdb-remote:5984/recipes", +}</programlisting> + + <para> + In all cases, the requested databases in the + <literal moreinfo="none">source</literal> and <literal moreinfo="none">target</literal> + specification must exist. If they do not, an error will be + returned within the JSON object: + </para> + +<programlisting format="linespecific">{ + "error" : "db_not_found" + "reason" : "could not open http://couchdb-remote:5984/ol1ka/", +}</programlisting> + + <para> + You can create the target database (providing your user + credentials allow it) by adding the + <literal moreinfo="none">create_target</literal> field to the request object: + </para> + +<programlisting format="linespecific">POST http://couchdb:5984/_replicate +Content-Type: application/json +Accept: application/json + +{ + "create_target" : true + "source" : "recipes", + "target" : "http://couchdb-remote:5984/recipes", +}</programlisting> + + <para> + The <literal moreinfo="none">create_target</literal> field is not destructive. + If the database already exists, the replication proceeds as + normal. + </para> + + </section> + + <section id="couchdb-api-misc_replicate_post-single"> + + <title>Single Replication</title> + + <para> + You can request replication of a database so that the two + databases can be synchronized. By default, the replication + process occurs one time and synchronizes the two databases + together. For example, you can request a single synchronization + between two databases by supplying the <literal moreinfo="none">source</literal> + and <literal moreinfo="none">target</literal> fields within the request JSON + content. + </para> + +<programlisting format="linespecific">POST http://couchdb:5984/_replicate +Content-Type: application/json +Accept: application/json + +{ + "source" : "recipes", + "target" : "recipes-snapshot", +}</programlisting> + + <para> + In the above example, the databases <literal moreinfo="none">recipes</literal> + and <literal moreinfo="none">recipes-snapshot</literal> will be synchronized. + These databases are local to the CouchDB instance where the + request was made. The response will be a JSON structure + containing the success (or failure) of the synchronization + process, and statistics about the process: + </para> + +<programlisting format="linespecific">{ + "ok" : true, + "history" : [ + { + "docs_read" : 1000, + "session_id" : "52c2370f5027043d286daca4de247db0", + "recorded_seq" : 1000, + "end_last_seq" : 1000, + "doc_write_failures" : 0, + "start_time" : "Thu, 28 Oct 2010 10:24:13 GMT", + "start_last_seq" : 0, + "end_time" : "Thu, 28 Oct 2010 10:24:14 GMT", + "missing_checked" : 0, + "docs_written" : 1000, + "missing_found" : 1000 + } + ], + "session_id" : "52c2370f5027043d286daca4de247db0", + "source_last_seq" : 1000 +}</programlisting> + + <para> + The structure defines the replication status, as described in + the table below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-misc-json-replication-status" class="jsonstructure"><title> + Replication Status + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">history</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + Replication History + </entry></row><row><entry> <literal moreinfo="none">doc_write_failures</literal> </entry><entry> + Number of document write failures + </entry></row><row><entry> <literal moreinfo="none">docs_read</literal> </entry><entry> + Number of documents read + </entry></row><row><entry> <literal moreinfo="none">docs_written</literal> </entry><entry> + Number of documents written to target + </entry></row><row><entry> <literal moreinfo="none">end_last_seq</literal> </entry><entry> + Last sequence number in changes stream + </entry></row><row><entry> <literal moreinfo="none">end_time</literal> </entry><entry> + Date/Time replication operation completed + </entry></row><row><entry> <literal moreinfo="none">missing_checked</literal> </entry><entry> + Number of missing documents checked + </entry></row><row><entry> <literal moreinfo="none">missing_found</literal> </entry><entry> + Number of missing documents found + </entry></row><row><entry> <literal moreinfo="none">recorded_seq</literal> </entry><entry> + Last recorded sequence number + </entry></row><row><entry> <literal moreinfo="none">session_id</literal> </entry><entry> + Session ID for this replication operation + </entry></row><row><entry> <literal moreinfo="none">start_last_seq</literal> </entry><entry> + First sequence number in changes stream + </entry></row><row><entry> <literal moreinfo="none">start_time</literal> </entry><entry> + Date/Time replication operation started + </entry></row><row><entry><literal moreinfo="none">ok</literal> </entry><entry> + Replication status + </entry></row><row><entry><literal moreinfo="none">session_id</literal> </entry><entry> + Unique session ID + </entry></row><row><entry><literal moreinfo="none">source_last_seq</literal> </entry><entry> + Last sequence number read from source database + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-api-misc_replicate_post-continuous"> + + <title>Continuous Replication</title> + + <para> + Synchronization of a database with the previously noted methods + happens only once, at the time the replicate request is made. To + have the target database permanently replicated from the source, + you must set the <literal moreinfo="none">continuous</literal> field of the JSON + object within the request to true. + </para> + + <para> + With continuous replication changes in the source database are + replicated to the target database in perpetuity until you + specifically request that replication ceases. + </para> + +<programlisting format="linespecific">POST http://couchdb:5984/_replicate +Content-Type: application/json +Accept: application/json + +{ + "continuous" : true + "source" : "recipes", + "target" : "http://couchdb-remote:5984/recipes", +}</programlisting> + + <para> + Changes will be replicated between the two databases as long as + a network connection is available between the two instances. + </para> + + <note> + <para> + Two keep two databases synchronized with each other, you need + to set replication in both directions; that is, you must + replicate from <literal moreinfo="none">databasea</literal> to + <literal moreinfo="none">databaseb</literal>, and separately from + <literal moreinfo="none">databaseb</literal> to <literal moreinfo="none">databasea</literal>. + </para> + </note> + + </section> + + <section id="couchdb-api-misc_replicate_post-cancel"> + + <title>Canceling Continuous Replication</title> + + <para> + You can cancel continuous replication by adding the + <literal moreinfo="none">cancel</literal> field to the JSON request object and + setting the value to true. Note that the structure of the + request must be identical to the original for the cancelation + request to be honoured. For example, if you requested continuous + replication, the cancellation request must also contain the + <literal moreinfo="none">continuous</literal> field. + </para> + + <para> + For example, the replication request: + </para> + +<programlisting format="linespecific">POST http://couchdb:5984/_replicate +Content-Type: application/json +Accept: application/json + +{ + "source" : "recipes", + "target" : "http://couchdb-remote:5984/recipes", + "create_target" : true, + "continuous" : true +}</programlisting> + + <para> + Must be canceled using the request: + </para> + +<programlisting format="linespecific">POST http://couchdb:5984/_replicate +Content-Type: application/json +Accept: application/json + +{ + "cancel" : true, + "continuous" : true + "create_target" : true, + "source" : "recipes", + "target" : "http://couchdb-remote:5984/recipes", +}</programlisting> + + <para> + Requesting cancellation of a replication that does not exist + results in a 404 error. + </para> + + </section> + + </section> + + <section id="couchdb-api-misc_restart_post"> + + <title><literal moreinfo="none">POST /_restart</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API POST /_restart</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">POST /_restart</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON status message + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">yes</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>201</entry><entry namest="info" nameend="addinfo"> + Document created successfully. + </entry></row></tbody></tgroup></informaltable> + + <para> + Restarts the CouchDB instance. You must be authenticated as a user + with administration privileges for this to work. + </para> + + <para> + For example: + </para> + +<programlisting format="linespecific">POST http://admin:password@couchdb:5984/_restart</programlisting> + + <para> + The return value (if the server has not already restarted) is a + JSON status object indicating that the request has been received: + </para> + +<programlisting format="linespecific">{ + "ok" : true, +}</programlisting> + + <para> + If the server has already restarted, the header may be returned, + but no actual data is contained in the response. + </para> + + </section> + + <section id="couchdb-api-misc_stats_get"> + + <title><literal moreinfo="none">GET /_stats</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /_stats</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /_stats</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Server statistics + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Request completed successfully. + </entry></row></tbody></tgroup></informaltable> + + <para> + The <literal moreinfo="none">_stats</literal> method returns a JSON object + containting the statistics for the running server. The object is + structured with top-level sections collating the statistics for a + range of entries, with each individual statistic being easily + identified, and the content of each statistic is self-describing. + For example, the request time statistics, within the + <literal moreinfo="none">couchdb</literal> section are structured as follows: + </para> + +<programlisting format="linespecific">{ + "couchdb" : { +... + "request_time" : { + "stddev" : "27.509", + "min" : "0.333333333333333", + "max" : "152", + "current" : "400.976", + "mean" : "10.837", + "sum" : "400.976", + "description" : "length of a request inside CouchDB without MochiWeb" + }, +... + } +}</programlisting> + + <para> + The fields provide the current, minimum and maximum, and a + collection of statistical means and quantities. The quantity in + each case is not defined, but the descriptions below provide + </para> + + <para> + The statistics are divided into the following top-level sections: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal moreinfo="none">couchdb</literal> + </para> + + <para> + Describes statistics specific to the internals of CouchDB. + </para> + + <table> + <title><literal moreinfo="none">couchdb</literal> statistics</title> + <tgroup cols="3"> + <colspec colname="stat"/> + <colspec colname="desc"/> + <colspec colname="unit"/> + <thead> + <row> + <entry> + Statistic ID + </entry> + <entry> + Description + </entry> + <entry> + Unit + </entry> + </row> + </thead> + <tbody> + <row> + <entry><literal moreinfo="none">auth_cache_hits</literal> + </entry> + <entry> + Number of authentication cache hits + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">auth_cache_misses</literal> + </entry> + <entry> + Number of authentication cache misses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">database_reads</literal> + </entry> + <entry> + Number of times a document was read from a database + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">database_writes</literal> + </entry> + <entry> + Number of times a database was changed + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">open_databases</literal> + </entry> + <entry> + Number of open databases + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">open_os_files</literal> + </entry> + <entry> + Number of file descriptors CouchDB has open + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">request_time</literal> + </entry> + <entry> + Length of a request inside CouchDB without MochiWeb + </entry> + <entry> + milliseconds + </entry> + </row> + </tbody> + </tgroup> + </table> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">httpd_request_methods</literal> + </para> + + <table> + <title><literal moreinfo="none">httpd_request_methods</literal> statistics</title> + <tgroup cols="3"> + <colspec colname="stat"/> + <colspec colname="desc"/> + <colspec colname="unit"/> + <thead> + <row> + <entry> + Statistic ID + </entry> + <entry> + Description + </entry> + <entry> + Unit + </entry> + </row> + </thead> + <tbody> + <row> + <entry><literal moreinfo="none">COPY</literal> + </entry> + <entry> + Number of HTTP COPY requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">DELETE</literal> + </entry> + <entry> + Number of HTTP DELETE requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">GET</literal> + </entry> + <entry> + Number of HTTP GET requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">HEAD</literal> + </entry> + <entry> + Number of HTTP HEAD requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">POST</literal> + </entry> + <entry> + Number of HTTP POST requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">PUT</literal> + </entry> + <entry> + Number of HTTP PUT requests + </entry> + <entry> + number + </entry> + </row> + </tbody> + </tgroup> + </table> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">httpd_status_codes</literal> + </para> + + <table> + <title><literal moreinfo="none">httpd_status_codes</literal> statistics</title> + <tgroup cols="3"> + <colspec colname="stat"/> + <colspec colname="desc"/> + <colspec colname="unit"/> + <thead> + <row> + <entry> + Statistic ID + </entry> + <entry> + Description + </entry> + <entry> + Unit + </entry> + </row> + </thead> + <tbody> + <row> + <entry><literal moreinfo="none">200</literal> + </entry> + <entry> + Number of HTTP 200 OK responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">201</literal> + </entry> + <entry> + Number of HTTP 201 Created responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">202</literal> + </entry> + <entry> + Number of HTTP 202 Accepted responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">301</literal> + </entry> + <entry> + Number of HTTP 301 Moved Permanently responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">304</literal> + </entry> + <entry> + Number of HTTP 304 Not Modified responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">400</literal> + </entry> + <entry> + Number of HTTP 400 Bad Request responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">401</literal> + </entry> + <entry> + Number of HTTP 401 Unauthorized responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">403</literal> + </entry> + <entry> + Number of HTTP 403 Forbidden responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">404</literal> + </entry> + <entry> + Number of HTTP 404 Not Found responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">405</literal> + </entry> + <entry> + Number of HTTP 405 Method Not Allowed responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">409</literal> + </entry> + <entry> + Number of HTTP 409 Conflict responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">412</literal> + </entry> + <entry> + Number of HTTP 412 Precondition Failed responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">500</literal> + </entry> + <entry> + Number of HTTP 500 Internal Server Error responses + </entry> + <entry> + number + </entry> + </row> + </tbody> + </tgroup> + </table> + </listitem> + + <listitem> + <para> + <literal moreinfo="none">httpd</literal> + </para> + + <table> + <title><literal moreinfo="none">httpd</literal> statistics</title> + <tgroup cols="3"> + <colspec colname="stat"/> + <colspec colname="desc"/> + <colspec colname="unit"/> + <thead> + <row> + <entry> + Statistic ID + </entry> + <entry> + Description + </entry> + <entry> + Unit + </entry> + </row> + </thead> + <tbody> + <row> + <entry><literal moreinfo="none">bulk_requests</literal> + </entry> + <entry> + Number of bulk requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">clients_requesting_changes</literal> + </entry> + <entry> + Number of clients for continuous _changes + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">requests</literal> + </entry> + <entry> + Number of HTTP requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">temporary_view_reads</literal> + </entry> + <entry> + Number of temporary view reads + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal moreinfo="none">view_reads</literal> + </entry> + <entry> + Number of view reads + </entry> + <entry> + number + </entry> + </row> + </tbody> + </tgroup> + </table> + </listitem> + + </itemizedlist> + + <para> + You can also access individual statistics by quoting the + statistics sections and statistic ID as part of the URL path. For + example, to get the <literal moreinfo="none">request_time</literal> statistics, + you can use: + </para> + +<programlisting format="linespecific">GET /_stats/couchdb/request_time</programlisting> + + <para> + This returns an entire statistics object, as with the full + request, but containining only the request individual statistic. + Hence, the returned structure is as follows: + </para> + +<programlisting format="linespecific">{ + "couchdb" : { + "request_time" : { + "stddev" : 7454.305, + "min" : 1, + "max" : 34185, + "current" : 34697.803, + "mean" : 1652.276, + "sum" : 34697.803, + "description" : "length of a request inside CouchDB without MochiWeb" + } + } +}</programlisting> + + </section> + + <section id="couchdb-api-misc_utils_get"> + + <title><literal moreinfo="none">GET /_utils</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /_utils</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /_utils</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Administration interface + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Accesses the built-in Futon administration interface for CouchDB. + </para> + + </section> + + <section id="couchdb-api-misc_uuids_get"> + + <title><literal moreinfo="none">GET /_uuids</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /_uuids</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /_uuids</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + List of UUIDs + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">count</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Number of UUIDs to return + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Request completed successfully. + </entry></row></tbody></tgroup></informaltable> + + <para> + Requests one or more Universally Unique Identifiers (UUIDs) from + the CouchDB instance. The response is a JSON object providing a + list of UUIDs. For example: + </para> + +<programlisting format="linespecific">{ + "uuids" : [ + "7e4b5a14b22ec1cf8e58b9cdd0000da3" + ] +}</programlisting> + + <para> + You can use the <literal moreinfo="none">count</literal> argument to specify the + number of UUIDs to be returned. For example: + </para> + +<programlisting format="linespecific">GET http://couchdb:5984/_uuids?count=5</programlisting> + + <para> + Returns: + </para> + +<programlisting format="linespecific">{ + "uuids" : [ + "c9df0cdf4442f993fc5570225b405a80", + "c9df0cdf4442f993fc5570225b405bd2", + "c9df0cdf4442f993fc5570225b405e42", + "c9df0cdf4442f993fc5570225b4061a0", + "c9df0cdf4442f993fc5570225b406a20" + ] +}</programlisting> + + <para> + The UUID type is determined by the UUID type setting in the + CouchDB configuration. See + <xref linkend="couchdb-api-config_config-section-key_put"/>. + </para> + + <para> + For example, changing the UUID type to <literal moreinfo="none">random</literal>: + </para> + +<programlisting format="linespecific">PUT http://couchdb:5984/_config/uuids/algorithm +Content-Type: application/json +Accept: */* + +"random"</programlisting> + + <para> + When obtaining a list of UUIDs: + </para> + +<programlisting format="linespecific">{ + "uuids" : [ + "031aad7b469956cf2826fcb2a9260492", + "6ec875e15e6b385120938df18ee8e496", + "cff9e881516483911aa2f0e98949092d", + "b89d37509d39dd712546f9510d4a9271", + "2e0dbf7f6c4ad716f21938a016e4e59f" + ] +}</programlisting> + + </section> + + <section id="couchdb-api-misc_favicon_get"> + + <title><literal moreinfo="none">GET /favicon.ico</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /favicon.ico</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /favicon.ico</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Binary content for the favicon.ico site icon + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Request completed successfully. + </entry></row><row><entry>404</entry><entry namest="info" nameend="addinfo"> + The requested content could not be found. The returned content + will include further information, as a JSON object, if available. + </entry></row></tbody></tgroup></informaltable> + + <para> + Returns the site icon. The return <literal moreinfo="none">Content-type</literal> + header is <literal moreinfo="none">image/x-icon</literal>, and the content stream + is the image data. + </para> + + </section> + +</chapter> + + <chapter id="couchdb-api-config"> + + <title>CouchDB API Server Configuration Methods</title> + + <para> + The CouchDB API Server Configuration Methods provide an interface to + query and update the various configuration values within a running + CouchDB instance. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-api-config-summary"><title>Configuration API Calls</title><tgroup cols="3"><colspec colname="method"/><colspec colname="path"/><colspec colname="desc"/><thead><row><entry>Method</entry><entry>Path</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/_config</literal></entry><entry><link linkend="couchdb-api-config_config_get"> + Obtain a list of the entire server configuration + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/_config/section</literal></entry><entry><link linkend="couchdb-api-config_config-section_get"> + Get all the configuration values for the specified section + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/_config/section/key</literal></entry><entry><link linkend="couchdb-api-config_config-section-key_get"> + Get a specific section/configuration value + </link></entry></row><row><entry><literal moreinfo="none">PUT</literal></entry><entry><literal moreinfo="none">/_config/section/key</literal></entry><entry><link linkend="couchdb-api-config_config-section-key_put"> + Set the specified configuration value + </link></entry></row><row><entry><literal moreinfo="none">DELETE</literal></entry><entry><literal moreinfo="none">/_config/section/key</literal></entry><entry><link linkend="couchdb-api-config_config-section-key_delete"> + Delete the current setting + </link></entry></row></tbody></tgroup></table> + + <section id="couchdb-api-config_config_get"> + + <title><literal moreinfo="none">GET /_config</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /_config</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /_config</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Returns a structure configuration name and value pairs, + organized by section + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Returns the entire CouchDB server configuration as a JSON + structure. The structure is organized by different configuration + sections, with individual values. + </para> + + <para> + For example, to get the configuration for a server: + </para> + +<programlisting format="linespecific">GET http://couchdb:5984/_config +Accept: application/json</programlisting> + + <para> + The response is the JSON structure: + </para> + +<programlisting format="linespecific">{ + "query_server_config" : { + "reduce_limit" : "true" + }, + "couchdb" : { + "os_process_timeout" : "5000", + "max_attachment_chunk_size" : "4294967296", + "max_document_size" : "4294967296", + "uri_file" : "/var/lib/couchdb/couch.uri", + "max_dbs_open" : "100", + "view_index_dir" : "/var/lib/couchdb", + "util_driver_dir" : "/usr/lib64/couchdb/erlang/lib/couch-1.0.1/priv/lib", + "database_dir" : "/var/lib/couchdb", + "delayed_commits" : "true" + }, + "attachments" : { + "compressible_types" : "text/*, application/javascript, application/json, application/xml", + "compression_level" : "8" + }, + "uuids" : { + "algorithm" : "utc_random" + }, + "daemons" : { + "view_manager" : "{couch_view, start_link, []}", + "auth_cache" : "{couch_auth_cache, start_link, []}", + "uuids" : "{couch_uuids, start, []}", + "stats_aggregator" : "{couch_stats_aggregator, start, []}", + "query_servers" : "{couch_query_servers, start_link, []}", + "httpd" : "{couch_httpd, start_link, []}", + "stats_collector" : "{couch_stats_collector, start, []}", + "db_update_notifier" : "{couch_db_update_notifier_sup, start_link, []}", + "external_manager" : "{couch_external_manager, start_link, []}" + }, + "stats" : { + "samples" : "[0, 60, 300, 900]", + "rate" : "1000" + }, + "httpd" : { + "vhost_global_handlers" : "_utils, _uuids, _session, _oauth, _users", + "secure_rewrites" : "true", + "authentication_handlers" : "{couch_httpd_oauth, oauth_authentication_handler}, + {couch_httpd_auth, cookie_authentication_handler}, + {couch_httpd_auth, default_authentication_handler}", + "port" : "5984", + "default_handler" : "{couch_httpd_db, handle_request}", + "allow_jsonp" : "false", + "bind_address" : "192.168.0.2", + "max_connections" : "2048" + }, + "query_servers" : { + "javascript" : "/usr/bin/couchjs /usr/share/couchdb/server/main.js" + }, + "couch_httpd_auth" : { + "authentication_db" : "_users", + "require_valid_user" : "false", + "authentication_redirect" : "/_utils/session.html", + "timeout" : "600", + "auth_cache_size" : "50" + }, + "httpd_db_handlers" : { + "_design" : "{couch_httpd_db, handle_design_req}", + "_compact" : "{couch_httpd_db, handle_compact_req}", + "_view_cleanup" : "{couch_httpd_db, handle_view_cleanup_req}", + "_temp_view" : "{couch_httpd_view, handle_temp_view_req}", + "_changes" : "{couch_httpd_db, handle_changes_req}" + }, + "replicator" : { + "max_http_sessions" : "10", + "max_http_pipeline_size" : "10" + }, + "log" : { + "include_sasl" : "true", + "level" : "info", + "file" : "/var/log/couchdb/couch.log" + }, + "httpd_design_handlers" : { + "_update" : "{couch_httpd_show, handle_doc_update_req}", + "_show" : "{couch_httpd_show, handle_doc_show_req}", + "_info" : "{couch_httpd_db, handle_design_info_req}", + "_list" : "{couch_httpd_show, handle_view_list_req}", + "_view" : "{couch_httpd_view, handle_view_req}", + "_rewrite" : "{couch_httpd_rewrite, handle_rewrite_req}" + }, + "httpd_global_handlers" : { + "_replicate" : "{couch_httpd_misc_handlers, handle_replicate_req}", + "/" : "{couch_httpd_misc_handlers, handle_welcome_req, <<\"Welcome\">>}", + "_config" : "{couch_httpd_misc_handlers, handle_config_req}", + "_utils" : "{couch_httpd_misc_handlers, handle_utils_dir_req, \"/usr/share/couchdb/www\"}", + "_active_tasks" : "{couch_httpd_misc_handlers, handle_task_status_req}", + "_session" : "{couch_httpd_auth, handle_session_req}", + "_log" : "{couch_httpd_misc_handlers, handle_log_req}", + "favicon.ico" : "{couch_httpd_misc_handlers, handle_favicon_req, \"/usr/share/couchdb/www\"}", + "_all_dbs" : "{couch_httpd_misc_handlers, handle_all_dbs_req}", + "_oauth" : "{couch_httpd_oauth, handle_oauth_req}", + "_restart" : "{couch_httpd_misc_handlers, handle_restart_req}", + "_uuids" : "{couch_httpd_misc_handlers, handle_uuids_req}", + "_stats" : "{couch_httpd_stats_handlers, handle_stats_req}" + } +}</programlisting> + + </section> + + <section id="couchdb-api-config_config-section_get"> + + <title><literal moreinfo="none">GET /_config/section</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /_config/section</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /_config/section</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + All the configuration values within a specified section + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Gets the configuration structure for a single section. For + example, to retrieve the CouchDB configuration section values: + </para> + +<programlisting format="linespecific">GET http://couchdb:5984/_config/couchdb +Accept: application/json</programlisting> + + <para> + The returned JSON contains just the configuration values for this + section: + </para> + +<programlisting format="linespecific">{ + "os_process_timeout" : "5000", + "max_attachment_chunk_size" : "4294967296", + "max_document_size" : "4294967296", + "uri_file" : "/var/lib/couchdb/couch.uri", + "max_dbs_open" : "100", + "view_index_dir" : "/var/lib/couchdb", + "util_driver_dir" : "/usr/lib64/couchdb/erlang/lib/couch-1.0.1/priv/lib", + "database_dir" : "/var/lib/couchdb", + "delayed_commits" : "true" +}</programlisting> + + </section> + + <section id="couchdb-api-config_config-section-key_get"> + + <title><literal moreinfo="none">GET /_config/section/key</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /_config/section/key</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">GET /_config/section/key</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Value of the specified key/section + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Gets a single configuration value from within a specific + configuration section. For example, to obtain the current log + level: + </para> + +<programlisting format="linespecific">GET http://couchdb:5984/_config/log/level +Accept: application/json</programlisting> + + <para> + Returns the string of the log level: + </para> + +<programlisting format="linespecific">"info"</programlisting> + + <note> + <para> + The returned value will be the JSON of the value, which may be a + string or numeric value, or an array or object. Some client + environments may not parse simple strings or numeric values as + valid JSON. + </para> + </note> + + </section> + + <section id="couchdb-api-config_config-section-key_put"> + + <title><literal moreinfo="none">PUT /_config/section/key</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API PUT /_config/section/key</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">PUT /_config/section/key</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + Value structure + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Previous value + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Configuration option updated successfully + </entry></row><row><entry>500</entry><entry namest="info" nameend="addinfo"> + Error setting configuration + </entry></row></tbody></tgroup></informaltable> + + <para> + Updates a configuration value. The new value should be supplied in + the request body in the corresponding JSON format. For example, if + you are setting a string value, you must supply a valid JSON + string. + </para> + + <para> + For example, to set the function used to generate UUIDs by the + <literal moreinfo="none">GET /_uuids</literal> API call to use the + <literal moreinfo="none">utc_random</literal> generator: + </para> + +<programlisting format="linespecific">PUT http://couchdb:5984/_config/uuids/algorithm +Content-Type: application/json + +"utc_random"</programlisting> + + <para> + The return value will be empty, with the response code indicating + the success or failure of the configuration setting. + </para> + + </section> + + <section id="couchdb-api-config_config-section-key_delete"> + + <title><literal moreinfo="none">DELETE /_config/section/key</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API DELETE /_config/section/key</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal moreinfo="none">DELETE /_config/section/key</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Previous value + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal moreinfo="none">rev</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry> + Current revision of the document for validation + </entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal moreinfo="none">If-Match</literal></entry></row><row><entry/><entry><emphasis role="bold">Description</emphasis></entry><entry>Current revision of the document for validation</entry></row><row><entry/><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry/><entry/><entry/></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>409</entry><entry namest="info" nameend="addinfo"> + Supplied revision is incorrect or missing + </entry></row></tbody></tgroup></informaltable> + + <para> + Deletes a configuration value. The returned JSON will be the value + of the configuration parameter before it was deleted. For example, + to delete the UUID parameter: + </para> + +<programlisting format="linespecific">DELETE http://couchdb:5984/_config/uuids/algorithm +Content-Type: application/json</programlisting> + + <para> + The returned value is the last configured UUID function: + </para> + +<programlisting format="linespecific">"random"</programlisting> + + </section> + +</chapter> + + <chapter id="couchdb-api-auth"> + + <title>CouchDB API Server Authentication Methods</title> + + <para> + The CouchDB Authentication methods provide an interface for + obtaining session and authorization data. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-api-auth-summary"><title>Authentication API Calls</title><tgroup cols="3"><colspec colname="method"/><colspec colname="path"/><colspec colname="desc"/><thead><row><entry>Method</entry><entry>Path</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/_oauth/access_token</literal></entry><entry><link linkend="couchdb-api-auth_access-token_get"> + TBC + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/_oauth/authorize</literal></entry><entry><link linkend="couchdb-api-auth_authorize_get"> + TBC + </link></entry></row><row><entry><literal moreinfo="none">POST</literal></entry><entry><literal moreinfo="none">/_oauth/authorize</literal></entry><entry><link linkend="couchdb-api-auth_authorize_post"> + TBC + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/_oauth/request_token</literal></entry><entry><link linkend="couchdb-api-auth_authorize_get"> + TBC + </link></entry></row><row><entry><literal moreinfo="none">GET</literal></entry><entry><literal moreinfo="none">/_session</literal></entry><entry><link linkend="couchdb-api-auth_session_get"> + Returns cookie based login user information + </link></entry></row><row><entry><literal moreinfo="none">POST</literal></entry><entry><literal moreinfo="none">/_session</literal></entry><entry><link linkend="couchdb-api-auth_session_post"> + Do cookie based user login + </link></entry></row><row><entry><literal moreinfo="none">DELETE</literal></entry><entry><literal moreinfo="none">/_session</literal></entry><entry><link linkend="couchdb-api-auth_session_delete"> + Logout cookie based user + </link></entry></row></tbody></tgroup></table> + +</chapter> + + <chapter id="couchdb-single-configuration"> + + <title>Configuring CouchDB</title> + + <para> + + </para> + + <section id="couchdb-single-configuration-files"> + + <title>CouchDB Configuration Files</title> + + <para> + + </para> + + </section> + + <section id="couchdb-single-configuration-files-locations"> + + <title>Configuration File Locations</title> + + <para> + CouchDB reads files from the following locations, in the following + order. + </para> + + <orderedlist inheritnum="ignore" continuation="restarts"> + + <listitem> + <para> + <filename moreinfo="none">PREFIX/default.ini</filename> + </para> + </listitem> + + <listitem> + <para> + <filename moreinfo="none">PREFIX/default.d/*</filename> + </para> + </listitem> + + <listitem> + <para> + <filename moreinfo="none">PREFIX/local.ini</filename> + </para> + </listitem> + + <listitem> + <para> + <filename moreinfo="none">PREFIX/local.d/*</filename> + </para> + </listitem> + + </orderedlist> + + <para> + Settings in successive documents override the settings in earlier + entries. For example, setting the <literal moreinfo="none">bind_address</literal> + parameter in <filename moreinfo="none">local.ini</filename> would override any + setting in <literal moreinfo="none">default.ini</literal>. + </para> + + <warning> + <para> + The <filename moreinfo="none">default.ini</filename> file may be overwritten + during an upgrade or re-installation, so localised changes + should be made to the <filename moreinfo="none">local.ini</filename> file or + files within the <filename moreinfo="none">local.d</filename> directory. + </para> + </warning> + + </section> + + <section id="couchdb-single-configuration-mochiweb"> + + <title>MochiWeb Server Options</title> + + <para> + Server options for the MochiWeb component of CouchDB can be added + to the configuration files. Settings should be added to the + <literal moreinfo="none">server_options</literal> option of the + <literal moreinfo="none">[httpd]</literal> section of + <filename moreinfo="none">local.ini</filename>. For example: + </para> + +<programlisting format="linespecific">[httpd] +server_options = [{backlog, 128}, {acceptor_pool_size, 16}]</programlisting> + + </section> + + <section id="couchdb-single-configuration-osprocess"> + + <title>OS Daemons</title> + + <para> + CouchDB now supports starting external processes. The support is + simple and enables CouchDB to start each configured OS daemon. If + the daemon stops at any point, CouchDB will restart it (with + protection to ensure regularly failing daemons are not repeatedly + restarted). + </para> + + <para> + The daemon starting process is one-to-one; for each each + configured daemon in the configuration file, CouchDB will start + exactly one instance. If you need to run multiple instances, then + you must create separate individual configurations. Daemons are + configured within the <literal moreinfo="none">[os_daemons]</literal> section of + your configuration file (<filename moreinfo="none">local.ini</filename>). The + format of each configured daemon is: + </para> + +<programlisting format="linespecific">NAME = PATH ARGS</programlisting> + + <para> + Where <literal moreinfo="none">NAME</literal> is an arbitrary (and unique) name to + identify the daemon; <literal moreinfo="none">PATH</literal> is the full path to + the daemon to be executed; <literal moreinfo="none">ARGS</literal> are any + required arguments to the daemon. + </para> + + <para> + For example: + </para> + +<programlisting format="linespecific">[os_daemons] +basic_responder = /usr/local/bin/responsder.js</programlisting> + + <para> + There is no interactivity between CouchDB and the running process, + but you can use the OS Daemons service to create new HTTP servers + and responders and then use the new proxy service to redirect + requests and output to the CouchDB managed service. For more + information on proxying, see + <xref linkend="couchdb-single-features-proxying"/>. For + further background on the OS Daemon service, see + <ulink url="http://davispj.com/2010/09/26/new-couchdb-externals-api.html">CouchDB + Externals API</ulink> + </para> + + </section> + + <section id="couchdb-single-configuration-update_notification"> + + <title>Update Notifications</title> + + <para> + + </para> + + </section> + + <section id="couchdb-single-configuration-socketoptions"> + + <title>Socket Options Configuration Setting</title> + + <para> + The socket options for the listening socket in CouchDB can now be + set within the CouchDB configuration file. The setting should be + added to the <literal moreinfo="none">[httpd]</literal> section of the file using + the option name <literal moreinfo="none">socket_options</literal>. The + specification is as a list of tuples. For example: + </para> + +<programlisting format="linespecific">[httpd] +socket_options = [{recbuf, 262144}, {sndbuf, 262144}, {nodelay, true}]</programlisting> + + <para> + The options supported are a subset of full options supported by + the TCP/IP stack. A list of the supported options are provided in + the + <ulink url="http://www.erlang.org/doc/man/inet.html#setopts-2">Erlang + inet</ulink> documentation. + </para> + + </section> + + <section id="couchdb-single-configuration-vhost"> + + <title><literal moreinfo="none">vhosts</literal> definitions</title> + + <para> + Similar to the rewrites section of a <literal moreinfo="none">_design</literal> + document, the <literal moreinfo="none">vhosts</literal> system uses variables in + the form of :varname or wildcards in the form of asterisks. The + variable results can be output into the resulting path as they are + in the rewriter. + </para> + + </section> + + <section id="couchdb-single-configuration-ssl"> + + <title>Configuring SSL Network Sockets</title> + + <para> + SSL configuration in CouchDB was designed to be as easy as + possible. All you need is two files; a certificate and a private + key. If you bought an official SSL certificate from a certificate + authority, both should be in your possession already. + </para> + + <para> + If you just want to try this out and don't want to pay anything + upfront, you can create a self-signed certificate. Everything will + work the same, but clients will get a warning about an insecure + certificate. + </para> + + <para> + You will need the OpenSSL command line tool installed. It probably + already is. + </para> + +<programlisting format="linespecific">shell> <userinput moreinfo="none">mkdir cert && cd cert</userinput> +shell> <userinput moreinfo="none">openssl genrsa > privkey.pem</userinput> +shell> <userinput moreinfo="none">openssl req -new -x509 -key privkey.pem -out mycert.pem -days 1095</userinput> +shell> <userinput moreinfo="none">ls</userinput> +mycert.pem privkey.pem</programlisting> + + <para> + Now, you need to edit CouchDB's configuration, either by editing + your <filename moreinfo="none">local.ini</filename> file or using the + <literal moreinfo="none">/_config</literal> API calls or the configuration screen + in Futon. Here is what you need to do in + <filename moreinfo="none">local.ini</filename>, you can infer what needs doing in + the other places. + </para> + + <para> + Be sure to make these edits. Under <literal moreinfo="none">[daemons]</literal> + you should see: + </para> + +<programlisting format="linespecific">; enable SSL support by uncommenting the following line and supply the PEM's below. +; the default ssl port CouchDB listens on is 6984 +;httpsd = {couch_httpd, start_link, [https]}</programlisting> + + <para> + Here uncomment the last line: + </para> + +<programlisting format="linespecific">httpsd = {couch_httpd, start_link, [https]}</programlisting> + + <para> + Next, under <literal moreinfo="none">[ssl]</literal> you will see: + </para> + +<programlisting format="linespecific">;cert_file = /full/path/to/server_cert.pem +;key_file = /full/path/to/server_key.pem</programlisting> + + <para> + Uncomment and adjust the paths so it matches your system's paths: + </para> + +<programlisting format="linespecific">cert_file = /home/jan/cert/mycert.pem +key_file = /home/jan/cert/privkey.pem</programlisting> + + <para> + For more information please read + <ulink url="http://www.openssl.org/docs/HOWTO/certificates.txt">http://www.openssl.org/docs/HOWTO/certificates.txt</ulink>. + </para> + + <para> + Now start (or restart) CouchDB. You should be able to connect to + it using HTTPS on port 6984: + </para> + +<programlisting format="linespecific">shell> <userinput moreinfo="none">curl https://127.0.0.1:6984/</userinput> +curl: (60) SSL certificate problem, verify that the CA cert is OK. Details: +error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed +More details here: http://curl.haxx.se/docs/sslcerts.html + +curl performs SSL certificate verification by default, using a "bundle" +of Certificate Authority (CA) public keys (CA certs). If the default +bundle file isn't adequate, you can specify an alternate file +using the --cacert option. +If this HTTPS server uses a certificate signed by a CA represented in +the bundle, the certificate verification probably failed due to a +problem with the certificate (it might be expired, or the name might +not match the domain name in the URL). +If you'd like to turn off curl's verification of the certificate, use +the -k (or --insecure) option.</programlisting> + + <para> + Oh no what happened?! — Remember, clients will notify their + users that your certificate is self signed. + <command moreinfo="none">curl</command> is the client in this case and it notifies + you. Luckily you trust yourself (don't you?) and you can specify + the <option>-k</option> option as the message reads: + </para> + +<programlisting format="linespecific">shell> <userinput moreinfo="none">curl -k https://127.0.0.1:6984/</userinput> +{"couchdb":"Welcome","version":"1.1.0"}</programlisting> + + </section> + + <section id="couchdb-single-config-options"> + + <title>CouchDB Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="section"/><colspec colname="desc"/><thead><row><entry>Section</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">attachments</literal></entry><entry> + Attachment options + </entry></row><row><entry><literal moreinfo="none">couchdb</literal></entry><entry> + CouchDB specific options + </entry></row><row><entry><literal moreinfo="none">daemons</literal></entry><entry> + Daemons and background processes + </entry></row><row><entry><literal moreinfo="none">httpd_db_handlers</literal></entry><entry> + Database Operation handlers + </entry></row><row><entry><literal moreinfo="none">couch_httpd_auth</literal></entry><entry> + HTTPD Authentication options + </entry></row><row><entry><literal moreinfo="none">httpd</literal></entry><entry> + HTTPD Server options + </entry></row><row><entry><literal moreinfo="none">httpd_design_handlers</literal></entry><entry> + Handlers for design document operations + </entry></row><row><entry><literal moreinfo="none">httpd_global_handlers</literal></entry><entry> + Handlers for global operations + </entry></row><row><entry><literal moreinfo="none">log</literal></entry><entry> + Logging options + </entry></row><row><entry><literal moreinfo="none">query_servers</literal></entry><entry> + Query Server options + </entry></row><row><entry><literal moreinfo="none">query_server_config</literal></entry><entry> + Query server options + </entry></row><row><entry><literal moreinfo="none">replicator</literal></entry><entry> + Replicator Options + </entry></row><row><entry><literal moreinfo="none">ssl</literal></entry><entry> + SSL (Secure Sockets Layer) Options + </entry></row><row><entry><literal moreinfo="none">stats</literal></entry><entry> + Statistics options + </entry></row><row><entry><literal moreinfo="none">uuids</literal></entry><entry> + UUID generation options + </entry></row></tbody></tgroup></table> + + <section id="couchdb-single-config-options_attachments"> + + <title><literal moreinfo="none">attachments</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-attachments-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">compressible_types</literal></entry><entry> + compressible_types + </entry></row><row><entry><literal moreinfo="none">compression_level</literal></entry><entry> + compression_level + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_couchdb"> + + <title><literal moreinfo="none">couchdb</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-couchdb-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">database_dir</literal></entry><entry> + database_dir + </entry></row><row><entry><literal moreinfo="none">delayed_commits</literal></entry><entry> + delayed_commits + </entry></row><row><entry><literal moreinfo="none">max_attachment_chunk_size</literal></entry><entry> + max_attachment_chunk_size + </entry></row><row><entry><literal moreinfo="none">max_dbs_open</literal></entry><entry> + max_dbs_open + </entry></row><row><entry><literal moreinfo="none">max_document_size</literal></entry><entry> + max_document_size + </entry></row><row><entry><literal moreinfo="none">os_process_timeout</literal></entry><entry> + os_process_timeout + </entry></row><row><entry><literal moreinfo="none">uri_file</literal></entry><entry> + uri_file + </entry></row><row><entry><literal moreinfo="none">util_driver_dir</literal></entry><entry> + util_driver_dir + </entry></row><row><entry><literal moreinfo="none">view_index_dir</literal></entry><entry> + view_index_dir + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_daemons"> + + <title><literal moreinfo="none">daemons</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-daemons-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">httpsd</literal></entry><entry> + Enabled HTTPS service + </entry></row><row><entry><literal moreinfo="none">auth_cache</literal></entry><entry> + auth_cache + </entry></row><row><entry><literal moreinfo="none">db_update_notifier</literal></entry><entry> + db_update_notifier + </entry></row><row><entry><literal moreinfo="none">external_manager</literal></entry><entry> + external_manager + </entry></row><row><entry><literal moreinfo="none">httpd</literal></entry><entry> + httpd + </entry></row><row><entry><literal moreinfo="none">query_servers</literal></entry><entry> + query_servers + </entry></row><row><entry><literal moreinfo="none">stats_aggregator</literal></entry><entry> + stats_aggregator + </entry></row><row><entry><literal moreinfo="none">stats_collector</literal></entry><entry> + stats_collector + </entry></row><row><entry><literal moreinfo="none">uuids</literal></entry><entry> + uuids + </entry></row><row><entry><literal moreinfo="none">view_manager</literal></entry><entry> + view_manager + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_httpd_db_handlers"> + + <title><literal moreinfo="none">httpd_db_handlers</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-httpd_db_handlers-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">_changes</literal></entry><entry> + _changes + </entry></row><row><entry><literal moreinfo="none">_compact</literal></entry><entry> + _compact + </entry></row><row><entry><literal moreinfo="none">_design</literal></entry><entry> + _design + </entry></row><row><entry><literal moreinfo="none">_temp_view</literal></entry><entry> + _temp_view + </entry></row><row><entry><literal moreinfo="none">_view_cleanup</literal></entry><entry> + _view_cleanup + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_couch_httpd_auth"> + + <title><literal moreinfo="none">couch_httpd_auth</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-couch_httpd_auth-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">auth_cache_size</literal></entry><entry> + auth_cache_size + </entry></row><row><entry><literal moreinfo="none">authentication_db</literal></entry><entry> + authentication_db + </entry></row><row><entry><literal moreinfo="none">authentication_redirect</literal></entry><entry> + authentication_redirect + </entry></row><row><entry><literal moreinfo="none">require_valid_user</literal></entry><entry> + require_valid_user + </entry></row><row><entry><literal moreinfo="none">timeout</literal></entry><entry> + timeout + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_httpd"> + + <title><literal moreinfo="none">httpd</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-httpd-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">nodelay</literal></entry><entry> + Enable TCP_NODELAY + </entry></row><row><entry><literal moreinfo="none">allow_jsonp</literal></entry><entry> + allow_jsonp + </entry></row><row><entry><literal moreinfo="none">authentication_handlers</literal></entry><entry> + authentication_handlers + </entry></row><row><entry><literal moreinfo="none">bind_address</literal></entry><entry> + bind_address + </entry></row><row><entry><literal moreinfo="none">default_handler</literal></entry><entry> + default_handler + </entry></row><row><entry><literal moreinfo="none">max_connections</literal></entry><entry> + max_connections + </entry></row><row><entry><literal moreinfo="none">port</literal></entry><entry> + port + </entry></row><row><entry><literal moreinfo="none">secure_rewrites</literal></entry><entry> + secure_rewrites + </entry></row><row><entry><literal moreinfo="none">vhost_global_handlers</literal></entry><entry> + vhost_global_handlers + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_httpd_design_handlers"> + + <title><literal moreinfo="none">httpd_design_handlers</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-httpd_design_handlers-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">_info</literal></entry><entry> + _info + </entry></row><row><entry><literal moreinfo="none">_list</literal></entry><entry> + _list + </entry></row><row><entry><literal moreinfo="none">_rewrite</literal></entry><entry> + _rewrite + </entry></row><row><entry><literal moreinfo="none">_show</literal></entry><entry> + _show + </entry></row><row><entry><literal moreinfo="none">_update</literal></entry><entry> + _update + </entry></row><row><entry><literal moreinfo="none">_view</literal></entry><entry> + _view + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_httpd_global_handlers"> + + <title><literal moreinfo="none">httpd_global_handlers</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-httpd_global_handlers-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">/</literal></entry><entry> + / + </entry></row><row><entry><literal moreinfo="none">_active_tasks</literal></entry><entry> + _active_tasks + </entry></row><row><entry><literal moreinfo="none">_all_dbs</literal></entry><entry> + _all_dbs + </entry></row><row><entry><literal moreinfo="none">_config</literal></entry><entry> + _config + </entry></row><row><entry><literal moreinfo="none">_log</literal></entry><entry> + _log + </entry></row><row><entry><literal moreinfo="none">_oauth</literal></entry><entry> + _oauth + </entry></row><row><entry><literal moreinfo="none">_replicate</literal></entry><entry> + _replicate + </entry></row><row><entry><literal moreinfo="none">_restart</literal></entry><entry> + _restart + </entry></row><row><entry><literal moreinfo="none">_session</literal></entry><entry> + _session + </entry></row><row><entry><literal moreinfo="none">_stats</literal></entry><entry> + _stats + </entry></row><row><entry><literal moreinfo="none">_utils</literal></entry><entry> + _utils + </entry></row><row><entry><literal moreinfo="none">_uuids</literal></entry><entry> + _uuids + </entry></row><row><entry><literal moreinfo="none">favicon.ico</literal></entry><entry> + favicon.ico + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_log"> + + <title><literal moreinfo="none">log</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-log-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">file</literal></entry><entry> + file + </entry></row><row><entry><literal moreinfo="none">include_sasl</literal></entry><entry> + include_sasl + </entry></row><row><entry><literal moreinfo="none">level</literal></entry><entry> + level + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_query_servers"> + + <title><literal moreinfo="none">query_servers</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-query_servers-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">javascript</literal></entry><entry> + javascript + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_query_server_config"> + + <title><literal moreinfo="none">query_server_config</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-query_server_config-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">reduce_limit</literal></entry><entry> + reduce_limit + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_replicator"> + + <title><literal moreinfo="none">replicator</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-replicator-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">max_http_pipeline_size</literal></entry><entry> + max_http_pipeline_size + </entry></row><row><entry><literal moreinfo="none">max_http_sessions</literal></entry><entry> + max_http_sessions + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_stats"> + + <title><literal moreinfo="none">stats</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-stats-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">rate</literal></entry><entry> + rate + </entry></row><row><entry><literal moreinfo="none">samples</literal></entry><entry> + samples + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_uuids"> + + <title><literal moreinfo="none">uuids</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-uuids-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal moreinfo="none">algorithm</literal></entry><entry> + algorithm + </entry></row></tbody></tgroup></table> + + </section> + +</section> + +</chapter> + + + + <appendix id="couchdb-api-json"> + + <title>JSON Structure Reference</title> + + <para> + The following appendix provides a quick reference to all the JSON + structures that you can supply to CouchDB, or get in return to + requests. + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-json-summary"><title>JSON Structures</title><tgroup cols="1"><colspec colname="desc"/><thead><row><entry>Description</entry></row></thead><tbody><row><entry><link linkend="table-couchdb-api-json_all-docs"> + All Database Documents + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_bulkdocsreturn"> + Bulk Document Response + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_bulkdocs"> + Bulk Documents + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_changes"> + Changes information for a database + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_document"> + CouchDB Document + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_jsonerror"> + CouchDB Error Status + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_db-info"> + CouchDB database information object + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_design-doc"> + Design Document + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_design-doc_info"> + Design Document Information + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_design-doc_info-spatial"> + Design Document spatial index Information + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_document_with_attachments"> + Document with Attachments + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_activetasks"> + List of Active Tasks + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_replication"> + Replication Settings + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_replication-status"> + Replication Status + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_document_with_revs_info"> + Returned CouchDB Document with Detailed Revision Info + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_document_with_revs"> + Returned CouchDB Document with Revision Info + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_returneddocument_with_attachments"> + Returned Document with Attachments + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_security"> + Security Object + </link></entry></row></tbody></tgroup></table> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-json_all-docs" class="jsonstructure"><title> + All Database Documents + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">offset</literal> </entry><entry> + Offset where the document list started + </entry></row><row><entry><literal moreinfo="none">rows</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + Array of document object + </entry></row><row><entry><literal moreinfo="none">total_rows</literal> </entry><entry> + Number of documents in the database/view + </entry></row><row><entry><literal moreinfo="none">update_seq</literal> (optional) </entry><entry> + Current update sequence for the database + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_bulkdocsreturn" class="jsonstructure"><title> + Bulk Document Response + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">docs</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + Bulk Docs Returned Documents + </entry></row><row><entry> <literal moreinfo="none">error</literal> </entry><entry> + Error type + </entry></row><row><entry> <literal moreinfo="none">id</literal> </entry><entry> + Document ID + </entry></row><row><entry> <literal moreinfo="none">reason</literal> </entry><entry> + Error string with extended reason + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_bulkdocs" class="jsonstructure"><title> + Bulk Documents + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">all_or_nothing</literal> (optional) </entry><entry> + Sets the database commit mode to use all-or-nothing semantics + </entry></row><row><entry><literal moreinfo="none">docs</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + Bulk Documents Document + </entry></row><row><entry> <literal moreinfo="none">_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry> <literal moreinfo="none">_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row><row><entry> <literal moreinfo="none">_deleted</literal> (optional) </entry><entry> + Whether the document should be deleted + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_changes" class="jsonstructure"><title> + Changes information for a database + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">last_seq</literal> </entry><entry> + Last change sequence number + </entry></row><row><entry><literal moreinfo="none">results</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + Changes made to a database + </entry></row><row><entry> <literal moreinfo="none">changes</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + List of changes, field-by-field, for this document + </entry></row><row><entry> <literal moreinfo="none">id</literal> </entry><entry> + Document ID + </entry></row><row><entry> <literal moreinfo="none">seq</literal> </entry><entry> + Update sequence number + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_document" class="jsonstructure"><title> + CouchDB Document + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry><literal moreinfo="none">_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_jsonerror" class="jsonstructure"><title> + CouchDB Error Status + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">error</literal> </entry><entry> + Error type + </entry></row><row><entry><literal moreinfo="none">id</literal> </entry><entry> + Document ID + </entry></row><row><entry><literal moreinfo="none">reason</literal> </entry><entry> + Error string with extended reason + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_db-info" class="jsonstructure"><title> + CouchDB database information object + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">committed_update_seq</literal> </entry><entry> + The number of committed update. + </entry></row><row><entry><literal moreinfo="none">compact_running</literal> </entry><entry> + Set to true if the database compaction routine is operating on + this database. + </entry></row><row><entry><literal moreinfo="none">db_name</literal> </entry><entry> + The name of the database. + </entry></row><row><entry><literal moreinfo="none">disk_format_version</literal> </entry><entry> + The version of the physical format used for the data when it is + stored on disk. + </entry></row><row><entry><literal moreinfo="none">disk_size</literal> </entry><entry> + Size in bytes of the data as stored on the disk. Views indexes + are not included in the calculation. + </entry></row><row><entry><literal moreinfo="none">doc_count</literal> </entry><entry> + A count of the documents in the specified database. + </entry></row><row><entry><literal moreinfo="none">doc_del_count</literal> </entry><entry> + Number of deleted documents + </entry></row><row><entry><literal moreinfo="none">instance_start_time</literal> </entry><entry> + Timestamp of when the database was created, expressed in + milliseconds since the epoch. + </entry></row><row><entry><literal moreinfo="none">purge_seq</literal> </entry><entry> + The number of purge operations on the database. + </entry></row><row><entry><literal moreinfo="none">update_seq</literal> </entry><entry> + The current number of updates to the database. + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_design-doc" class="jsonstructure"><title> + Design Document + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">_id</literal> </entry><entry> + Design Document ID + </entry></row><row><entry><literal moreinfo="none">_rev</literal> </entry><entry> + Design Document Revision + </entry></row><row><entry><literal moreinfo="none">views</literal> </entry><entry> + View + </entry></row><row><entry> <literal moreinfo="none">viewname</literal> </entry><entry> + View Definition + </entry></row><row><entry> <literal moreinfo="none">map</literal> </entry><entry> + Map Function for View + </entry></row><row><entry> <literal moreinfo="none">reduce</literal> (optional) </entry><entry> + Reduce Function for View + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_design-doc_info" class="jsonstructure"><title> + Design Document Information + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">name</literal> </entry><entry> + Name/ID of Design Document + </entry></row><row><entry><literal moreinfo="none">view_index</literal> </entry><entry> + View Index + </entry></row><row><entry> <literal moreinfo="none">compact_running</literal> </entry><entry> + Indicates whether a compaction routine is currently running on + the view + </entry></row><row><entry> <literal moreinfo="none">disk_size</literal> </entry><entry> + Size in bytes of the view as stored on disk + </entry></row><row><entry> <literal moreinfo="none">language</literal> </entry><entry> + Language for the defined views + </entry></row><row><entry> <literal moreinfo="none">purge_seq</literal> </entry><entry> + The purge sequence that has been processed + </entry></row><row><entry> <literal moreinfo="none">signature</literal> </entry><entry> + MD5 signature of the views for the design document + </entry></row><row><entry> <literal moreinfo="none">update_seq</literal> </entry><entry> + The update sequence of the corresponding database that has been + indexed + </entry></row><row><entry> <literal moreinfo="none">updater_running</literal> </entry><entry> + Indicates if the view is currently being updated + </entry></row><row><entry> <literal moreinfo="none">waiting_clients</literal> </entry><entry> + Number of clients waiting on views from this design document + </entry></row><row><entry> <literal moreinfo="none">waiting_commit</literal> </entry><entry> + Indicates if there are outstanding commits to the underlying + database that need to processed + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_design-doc_info-spatial" class="jsonstructure"><title> + Design Document spatial index Information + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">name</literal> </entry><entry> + Name/ID of Design Document + </entry></row><row><entry><literal moreinfo="none">spatial_index</literal> </entry><entry> + View Index + </entry></row><row><entry> <literal moreinfo="none">compact_running</literal> </entry><entry> + Indicates whether a compaction routine is currently running on + the view + </entry></row><row><entry> <literal moreinfo="none">disk_size</literal> </entry><entry> + Size in bytes of the view as stored on disk + </entry></row><row><entry> <literal moreinfo="none">language</literal> </entry><entry> + Language for the defined views + </entry></row><row><entry> <literal moreinfo="none">purge_seq</literal> </entry><entry> + The purge sequence that has been processed + </entry></row><row><entry> <literal moreinfo="none">signature</literal> </entry><entry> + MD5 signature of the views for the design document + </entry></row><row><entry> <literal moreinfo="none">update_seq</literal> </entry><entry> + The update sequence of the corresponding database that has been + indexed + </entry></row><row><entry> <literal moreinfo="none">updater_running</literal> </entry><entry> + Indicates if the view is currently being updated + </entry></row><row><entry> <literal moreinfo="none">waiting_clients</literal> </entry><entry> + Number of clients waiting on views from this design document + </entry></row><row><entry> <literal moreinfo="none">waiting_commit</literal> </entry><entry> + Indicates if there are outstanding commits to the underlying + database that need to processed + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_document_with_attachments" class="jsonstructure"><title> + Document with Attachments + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry><literal moreinfo="none">_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row><row><entry><literal moreinfo="none">_attachments</literal> (optional) </entry><entry> + Document Attachment + </entry></row><row><entry> <literal moreinfo="none">filename</literal> </entry><entry> + Attachment information + </entry></row><row><entry> <literal moreinfo="none">content_type</literal> </entry><entry> + MIME Content type string + </entry></row><row><entry> <literal moreinfo="none">data</literal> </entry><entry> + File attachment content, Base64 encoded + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_activetasks" class="jsonstructure"><title> + List of Active Tasks + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">tasks</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + Active Task + </entry></row><row><entry> <literal moreinfo="none">pid</literal> </entry><entry> + Process ID + </entry></row><row><entry> <literal moreinfo="none">status</literal> </entry><entry> + Task status message + </entry></row><row><entry> <literal moreinfo="none">task</literal> </entry><entry> + Task name + </entry></row><row><entry> <literal moreinfo="none">type</literal> </entry><entry> + Operation Type + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_replication" class="jsonstructure"><title> + Replication Settings + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">cancel</literal> (optional) </entry><entry> + Cancels the replication + </entry></row><row><entry><literal moreinfo="none">continuous</literal> (optional) </entry><entry> + Configure the replication to be continuous + </entry></row><row><entry><literal moreinfo="none">create_target</literal> (optional) </entry><entry> + Creates the target database + </entry></row><row><entry><literal moreinfo="none">doc_ids</literal> (optional) </entry><entry> + Array of document IDs to be synchronized + </entry></row><row><entry><literal moreinfo="none">proxy</literal> (optional) </entry><entry> + Address of a proxy server through which replication should occur + </entry></row><row><entry><literal moreinfo="none">source</literal> </entry><entry> + Source database name or URL + </entry></row><row><entry><literal moreinfo="none">target</literal> </entry><entry> + Target database name or URL + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_replication-status" class="jsonstructure"><title> + Replication Status + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">history</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + Replication History + </entry></row><row><entry> <literal moreinfo="none">doc_write_failures</literal> </entry><entry> + Number of document write failures + </entry></row><row><entry> <literal moreinfo="none">docs_read</literal> </entry><entry> + Number of documents read + </entry></row><row><entry> <literal moreinfo="none">docs_written</literal> </entry><entry> + Number of documents written to target + </entry></row><row><entry> <literal moreinfo="none">end_last_seq</literal> </entry><entry> + Last sequence number in changes stream + </entry></row><row><entry> <literal moreinfo="none">end_time</literal> </entry><entry> + Date/Time replication operation completed + </entry></row><row><entry> <literal moreinfo="none">missing_checked</literal> </entry><entry> + Number of missing documents checked + </entry></row><row><entry> <literal moreinfo="none">missing_found</literal> </entry><entry> + Number of missing documents found + </entry></row><row><entry> <literal moreinfo="none">recorded_seq</literal> </entry><entry> + Last recorded sequence number + </entry></row><row><entry> <literal moreinfo="none">session_id</literal> </entry><entry> + Session ID for this replication operation + </entry></row><row><entry> <literal moreinfo="none">start_last_seq</literal> </entry><entry> + First sequence number in changes stream + </entry></row><row><entry> <literal moreinfo="none">start_time</literal> </entry><entry> + Date/Time replication operation started + </entry></row><row><entry><literal moreinfo="none">ok</literal> </entry><entry> + Replication status + </entry></row><row><entry><literal moreinfo="none">session_id</literal> </entry><entry> + Unique session ID + </entry></row><row><entry><literal moreinfo="none">source_last_seq</literal> </entry><entry> + Last sequence number read from source database + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_document_with_revs_info" class="jsonstructure"><title> + Returned CouchDB Document with Detailed Revision Info + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry><literal moreinfo="none">_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row><row><entry><literal moreinfo="none">_revs_info</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + CouchDB Document Extended Revision Info + </entry></row><row><entry> <literal moreinfo="none">rev</literal> </entry><entry> + Full revision string + </entry></row><row><entry> <literal moreinfo="none">status</literal> </entry><entry> + Status of the revision + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_document_with_revs" class="jsonstructure"><title> + Returned CouchDB Document with Revision Info + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry><literal moreinfo="none">_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row><row><entry><literal moreinfo="none">_revisions</literal> </entry><entry> + CouchDB Document Revisions + </entry></row><row><entry> <literal moreinfo="none">ids</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + Array of valid revision IDs, in reverse order (latest first) + </entry></row><row><entry> <literal moreinfo="none">start</literal> </entry><entry> + Prefix number for the latest revision + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_returneddocument_with_attachments" class="jsonstructure"><title> + Returned Document with Attachments + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry><literal moreinfo="none">_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row><row><entry><literal moreinfo="none">_attachments</literal> (optional) </entry><entry> + Document Attachment + </entry></row><row><entry> <literal moreinfo="none">filename</literal> </entry><entry> + Attachment + </entry></row><row><entry> <literal moreinfo="none">content_type</literal> </entry><entry> + MIME Content type string + </entry></row><row><entry> <literal moreinfo="none">length</literal> </entry><entry> + Length (bytes) of the attachment data + </entry></row><row><entry> <literal moreinfo="none">revpos</literal> </entry><entry> + Revision where this attachment exists + </entry></row><row><entry> <literal moreinfo="none">stub</literal> </entry><entry> + Indicates whether the attachment is a stub + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_security" class="jsonstructure"><title> + Security Object + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry><literal moreinfo="none">admins</literal> </entry><entry> + Roles/Users with admin privileges + </entry></row><row><entry> <literal moreinfo="none">roles</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + List of roles with parent privilege + </entry></row><row><entry> <literal moreinfo="none">users</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + List of users with parent privilege + </entry></row><row><entry><literal moreinfo="none">readers</literal> </entry><entry> + Roles/Users with reader privileges + </entry></row><row><entry> <literal moreinfo="none">roles</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + List of roles with parent privilege + </entry></row><row><entry> <literal moreinfo="none">users</literal> <literal moreinfo="none">[array]</literal> </entry><entry> + List of users with parent privilege + </entry></row></tbody></tgroup></table> + +</appendix> + +</book> diff --git a/share/docs/couchdb-manual-1.1/couchdb-manual.xml b/share/docs/couchdb-manual-1.1/couchdb-manual.xml new file mode 100644 index 000000000..3404b9270 --- /dev/null +++ b/share/docs/couchdb-manual-1.1/couchdb-manual.xml @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE book PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<book id="couchdb-__meta_version_id__"> + + <title>CouchDB __meta_version__ Manual</title> + + <bookinfo> + + <abstract> + + <para> + This manual documents the CouchDB + __meta_version__ database system, including the installation, + functionality, and CouchDB API. + </para> + + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="../common/docbuilddate.xml"/> + + </abstract> + + </bookinfo> + + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="couchdb-introduction.xml"/> + + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="couchdb-features.xml"/> + + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="couchdb-replication.xml"/> + +<!-- + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="metadoc-couchdb-changes.xml"/> + + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="couchdb-dbmaint.xml"/> + + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="couchdb-views.xml"/> + + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="couchdb-backuprestore.xml"/> +--> + + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="couchdb-api-introduction.xml"/> + + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="metadoc-couchdb-api-db.xml"/> + + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="metadoc-couchdb-api-dbdoc.xml"/> + + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="metadoc-couchdb-api-localdb.xml"/> + + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="metadoc-couchdb-api-design.xml"/> + + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="metadoc-couchdb-api-misc.xml"/> + + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="metadoc-couchdb-api-config.xml"/> + + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="metadoc-couchdb-api-auth.xml"/> + + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="couchdb-configuration.xml"/> + +<!-- Appendices --> + + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="metadoc-couchdb-api-json.xml"/> + +</book> diff --git a/share/docs/couchdb-manual-1.1/couchdb-replication.xml b/share/docs/couchdb-manual-1.1/couchdb-replication.xml new file mode 100644 index 000000000..a62a88434 --- /dev/null +++ b/share/docs/couchdb-manual-1.1/couchdb-replication.xml @@ -0,0 +1,554 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-single-replication"> + + <title>Replication</title> + + <para> + + </para> + + <section id="couchdb-single-replication-replicatordb"> + + <title>Replicator Database</title> + + <para> + A database where you + <literal>PUT</literal>/<literal>POST</literal> documents to + trigger replications and you <literal>DELETE</literal> to cancel + ongoing replications. These documents have exactly the same + content as the JSON objects we used to <literal>POST</literal> to + <literal>_replicate</literal> (fields <literal>source</literal>, + <literal>target</literal>, <literal>create_target</literal>, + <literal>continuous</literal>, <literal>doc_ids</literal>, + <literal>filter</literal>, <literal>query_params</literal>. + </para> + + <para> + Replication documents can have a user defined + <literal>_id</literal>. Design documents (and + <literal>_local</literal> documents) added to the replicator + database are ignored. + </para> + + <para> + The default name of this database is + <literal>_replicator</literal>. The name can be changed in the + <filename>local.ini</filename> configuration, section + <literal>[replicator]</literal>, parameter <literal>db</literal>. + </para> + + <section id="couchdb-single-replication-replicatordb-basics"> + + <title>Basics</title> + + <para> + Let's say you PUT the following document into _replicator: + </para> + +<programlisting> +{ + "_id": "my_rep", + "source": "http://myserver.com:5984/foo", + "target": "bar", + "create_target": true +} +</programlisting> + + <para> + In the couch log you'll see 2 entries like these: + </para> + +<programlisting> +[Thu, 17 Feb 2011 19:43:59 GMT] [info] [<0.291.0>] Document `my_rep` triggered replication `c0ebe9256695ff083347cbf95f93e280+create_target` +[Thu, 17 Feb 2011 19:44:37 GMT] [info] [<0.124.0>] Replication `c0ebe9256695ff083347cbf95f93e280+create_target` finished (triggered by document `my_rep`) +</programlisting> + + <para> + As soon as the replication is triggered, the document will be + updated by CouchDB with 3 new fields: + </para> + +<programlisting> +{ + "_id": "my_rep", + "source": "http://myserver.com:5984/foo", + "target": "bar", + "create_target": true, + "_replication_id": "c0ebe9256695ff083347cbf95f93e280", + "_replication_state": "triggered", + "_replication_state_time": 1297974122 +} +</programlisting> + + <para> + Special fields set by the replicator start with the prefix + <literal>_replication_</literal>. + </para> + + <itemizedlist> + + <listitem> + <para> + <literal>_replication_id</literal> + </para> + + <para> + The ID internally assigned to the replication. This is also + the ID exposed by <literal>/_active_tasks</literal>. + </para> + </listitem> + + <listitem> + <para> + <literal>_replication_state</literal> + </para> + + <para> + The current state of the replication. + </para> + </listitem> + + <listitem> + <para> + <literal>_replication_state_time</literal> + </para> + + <para> + A Unix timestamp (number of seconds since 1 Jan 1970) that + tells us when the current replication state (marked in + <literal>_replication_state</literal>) was set. + </para> + </listitem> + + </itemizedlist> + + <para> + When the replication finishes, it will update the + <literal>_replication_state</literal> field (and + <literal>_replication_state_time</literal>) with the value + <literal>completed</literal>, so the document will look like: + </para> + +<programlisting> +{ + "_id": "my_rep", + "source": "http://myserver.com:5984/foo", + "target": "bar", + "create_target": true, + "_replication_id": "c0ebe9256695ff083347cbf95f93e280", + "_replication_state": "completed", + "_replication_state_time": 1297974122 +} +</programlisting> + + <para> + When an error happens during replication, the + <literal>_replication_state</literal> field is set to + <literal>error</literal> (and + <literal>_replication_state</literal> gets updated of course). + </para> + + <para> + When you PUT/POST a document to the + <literal>_replicator</literal> database, CouchDB will attempt to + start the replication up to 10 times (configurable under + <literal>[replicator]</literal>, parameter + <literal>max_replication_retry_count</literal>). If it fails on + the first attempt, it waits 5 seconds before doing a second + attempt. If the second attempt fails, it waits 10 seconds before + doing a third attempt. If the third attempt fails, it waits 20 + seconds before doing a fourth attempt (each attempt doubles the + previous wait period). When an attempt fails, the Couch log will + show you something like: + </para> + +<programlisting> +[error] [<0.149.0>] Error starting replication `67c1bb92010e7abe35d7d629635f18b6+create_target` (document `my_rep_2`): {db_not_found,<<"could not open http://myserver:5986/foo/">> +</programlisting> + + <note> + <para> + The <literal>_replication_state</literal> field is only set to + <literal>error</literal> when all the attempts were + unsuccessful. + </para> + </note> + + <para> + There are only 3 possible values for the + <literal>_replication_state</literal> field: + <literal>triggered</literal>, <literal>completed</literal> and + <literal>error</literal>. Continuous replications never get + their state set to <literal>completed</literal>. + </para> + + </section> + + <section id="couchdb-single-replication-replicatordb-docsame"> + + <title>Documents describing the same replication</title> + + <para> + Lets suppose 2 documents are added to the + <literal>_replicator</literal> database in the following order: + </para> + +<programlisting> +{ + "_id": "doc_A", + "source": "http://myserver.com:5984/foo", + "target": "bar" +} +</programlisting> + + <para> + and + </para> + +<programlisting> +{ + "_id": "doc_B", + "source": "http://myserver.com:5984/foo", + "target": "bar" +} +</programlisting> + + <para> + Both describe exactly the same replication (only their + <literal>_ids</literal> differ). In this case document + <literal>doc_A</literal> triggers the replication, getting + updated by CouchDB with the fields + <literal>_replication_state</literal>, + <literal>_replication_state_time</literal> and + <literal>_replication_id</literal>, just like it was described + before. Document <literal>doc_B</literal> however, is only + updated with one field, the <literal>_replication_id</literal> + so it will look like this: + </para> + +<programlisting> +{ + "_id": "doc_B", + "source": "http://myserver.com:5984/foo", + "target": "bar", + "_replication_id": "c0ebe9256695ff083347cbf95f93e280" +} +</programlisting> + + <para> + While document <literal>doc_A</literal> will look like this: + </para> + +<programlisting> +{ + "_id": "doc_A", + "source": "http://myserver.com:5984/foo", + "target": "bar", + "_replication_id": "c0ebe9256695ff083347cbf95f93e280", + "_replication_state": "triggered", + "_replication_state_time": 1297974122 +} +</programlisting> + + <para> + Note that both document get exactly the same value for the + <literal>_replication_id</literal> field. This way you can + identify which documents refer to the same replication - you can + for example define a view which maps replication IDs to document + IDs. + </para> + + </section> + + <section id="couchdb-single-replication-replicatordb-cancel"> + + <title>Canceling replications</title> + + <para> + To cancel a replication simply <literal>DELETE</literal> the + document which triggered the replication. The Couch log will + show you an entry like the following: + </para> + +<programlisting> +[Thu, 17 Feb 2011 20:16:29 GMT] [info] [<0.125.0>] Stopped replication `c0ebe9256695ff083347cbf95f93e280+continuous+create_target` because replication document `doc_A` was deleted +</programlisting> + + <note> + <para> + You need to <literal>DELETE</literal> the document that + triggered the replication. <literal>DELETE</literal>ing + another document that describes the same replication but did + not trigger it, will not cancel the replication. + </para> + </note> + + </section> + + <section id="couchdb-single-replication-replicatordb-restart"> + + <title>Server restart</title> + + <para> + When CouchDB is restarted, it checks its + <literal>_replicator</literal> database and restarts any + replication that is described by a document that either has its + <literal>_replication_state</literal> field set to + <literal>triggered</literal> or it doesn't have yet the + <literal>_replication_state</literal> field set. + </para> + + <note> + <para> + Continuous replications always have a + <literal>_replication_state</literal> field with the value + <literal>triggered</literal>, therefore they're always + restarted when CouchDB is restarted. + </para> + </note> + + </section> + + <section id="couchdb-single-replication-replicatordb-changing"> + + <title>Changing the Replicator Database</title> + + <para> + Imagine your replicator database (default name is _replicator) + has the two following documents that represent pull replications + from servers A and B: + </para> + +<programlisting> +{ + "_id": "rep_from_A", + "source": "http://aserver.com:5984/foo", + "target": "foo_a", + "continuous": true, + "_replication_id": "c0ebe9256695ff083347cbf95f93e280", + "_replication_state": "triggered", + "_replication_state_time": 1297971311 +} +{ + "_id": "rep_from_B", + "source": "http://bserver.com:5984/foo", + "target": "foo_b", + "continuous": true, + "_replication_id": "231bb3cf9d48314eaa8d48a9170570d1", + "_replication_state": "triggered", + "_replication_state_time": 1297974122 +} +</programlisting> + + <para> + Now without stopping and restarting CouchDB, you change the name + of the replicator database to + <literal>another_replicator_db</literal>: + </para> + +<programlisting> +$ curl -X PUT http://localhost:5984/_config/replicator/db -d '"another_replicator_db"' +"_replicator" +</programlisting> + + <para> + As soon as this is done, both pull replications defined before, + are stopped. This is explicitly mentioned in CouchDB's log: + </para> + +<programlisting><![CDATA[ +[Fri, 11 Mar 2011 07:44:20 GMT] [info] [<0.104.0>] Stopping all ongoing replications because the replicator database was deleted or changed +[Fri, 11 Mar 2011 07:44:20 GMT] [info] [<0.127.0>] 127.0.0.1 - - PUT /_config/replicator/db 200 +]]> +</programlisting> + + <para> + Imagine now you add a replication document to the new replicator + database named <literal>another_replicator_db</literal>: + </para> + +<programlisting> +{ + "_id": "rep_from_X", + "source": "http://xserver.com:5984/foo", + "target": "foo_x", + "continuous": true +} +</programlisting> + + <para> + From now own you have a single replication going on in your + system: a pull replication pulling from server X. Now you change + back the replicator database to the original one + <literal>_replicator</literal>: + </para> + +<programlisting> +$ curl -X PUT http://localhost:5984/_config/replicator/db -d '"_replicator"' +"another_replicator_db" +</programlisting> + + <para> + Immediately after this operation, the replication pulling from + server X will be stopped and the replications defined in the + _replicator database (pulling from servers A and B) will be + resumed. + </para> + + <para> + Changing again the replicator database to + <literal>another_replicator_db</literal> will stop the pull + replications pulling from servers A and B, and resume the pull + replication pulling from server X. + </para> + + </section> + + <section id="couchdb-single-replication-replicatordb-replicating"> + + <title>Replicating the replicator database</title> + + <para> + Imagine you have in server C a replicator database with the two + following pull replication documents in it: + </para> + +<programlisting> +{ + "_id": "rep_from_A", + "source": "http://aserver.com:5984/foo", + "target": "foo_a", + "continuous": true, + "_replication_id": "c0ebe9256695ff083347cbf95f93e280", + "_replication_state": "triggered", + "_replication_state_time": 1297971311 +} +{ + "_id": "rep_from_B", + "source": "http://bserver.com:5984/foo", + "target": "foo_b", + "continuous": true, + "_replication_id": "231bb3cf9d48314eaa8d48a9170570d1", + "_replication_state": "triggered", + "_replication_state_time": 1297974122 +} +</programlisting> + + <para> + Now you would like to have the same pull replications going on + in server D, that is, you would like to have server D pull + replicating from servers A and B. You have two options: + </para> + + <itemizedlist> + + <listitem> + <para> + Explicitly add two documents to server's D replicator + database + </para> + </listitem> + + <listitem> + <para> + Replicate server's C replicator database into server's D + replicator database + </para> + </listitem> + + </itemizedlist> + + <para> + Both alternatives accomplish exactly the same goal. + </para> + + </section> + + <section id="couchdb-single-replication-replicatordb-delegations"> + + <title>Delegations</title> + + <para> + Replication documents can have a custom + <literal>user_ctx</literal> property. This property defines the + user context under which a replication runs. For the old way of + triggering replications (POSTing to + <literal>/_replicate/</literal>), this property was not needed + (it didn't exist in fact) - this is because at the moment of + triggering the replication it has information about the + authenticated user. With the replicator database, since it's a + regular database, the information about the authenticated user + is only present at the moment the replication document is + written to the database - the replicator database implementation + is like a _changes feed consumer (with + <literal>?include_docs=true</literal>) that reacts to what was + written to the replicator database - in fact this feature could + be implemented with an external script/program. This + implementation detail implies that for non admin users, a + <literal>user_ctx</literal> property, containing the user's name + and a subset of his/her roles, must be defined in the + replication document. This is ensured by the document update + validation function present in the default design document of + the replicator database. This validation function also ensure + that a non admin user can set a user name property in the + <literal>user_ctx</literal> property that doesn't match his/her + own name (same principle applies for the roles). + </para> + + <para> + For admins, the <literal>user_ctx</literal> property is + optional, and if it's missing it defaults to a user context with + name null and an empty list of roles - this mean design + documents will not be written to local targets. If writing + design documents to local targets is desired, the a user context + with the roles <literal>_admin</literal> must be set explicitly. + </para> + + <para> + Also, for admins the <literal>user_ctx</literal> property can be + used to trigger a replication on behalf of another user. This is + the user context that will be passed to local target database + document validation functions. + </para> + + <note> + <para> + The <literal>user_ctx</literal> property only has effect for + local endpoints. + </para> + </note> + + <para> + Example delegated replication document: + </para> + +<programlisting> +{ + "_id": "my_rep", + "source": "http://bserver.com:5984/foo", + "target": "bar", + "continuous": true, + "user_ctx": { + "name": "joe", + "roles": ["erlanger", "researcher"] + } +} +</programlisting> + + <para> + As stated before, for admins the user_ctx property is optional, + while for regular (non admin) users it's mandatory. When the + roles property of <literal>user_ctx</literal> is missing, it + defaults to the empty list <literal>[ ]</literal>. + </para> + + </section> + + </section> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/couchdb-single-troubleshooting.xml b/share/docs/couchdb-manual-1.1/couchdb-single-troubleshooting.xml new file mode 100644 index 000000000..5d72456f7 --- /dev/null +++ b/share/docs/couchdb-manual-1.1/couchdb-single-troubleshooting.xml @@ -0,0 +1,35 @@ + <section id="couchdb-single-features-errormessages"> + + <title>Error Messages</title> + + <para> + The errors reported when CouchDB is unable to read a required file + have been updated so that explicit information about the files and + problem can now be identified from the error message. The errors + report file permission access either when reading or writing to + configuration and database files. + </para> + + <para> + The error is raised both through the log file and the error + message returned through the API call as a JSON error message. For + example, when setting configuration values: + </para> + +<programlisting> +shell> <userinput>curl -H 'X-Couch-Persist: true' -X PUT http://couchdb:5984/_config/couchdb/delayed_commits -d '"false"'</userinput> +{"error":"file_permission_error","reason":"/etc/couchdb/local.ini"} + </programlisting> + + <para> + Errors will always be reported using the + <literal>file_permission_error</literal> error type. + </para> + + <para> + During startup permissions errors on key files are also reported + in the log with a descriptive error message and file location so + that permissions can be fixed before restart. + </para> + + </section> diff --git a/share/docs/couchdb-manual-1.1/couchdb-views.xml b/share/docs/couchdb-manual-1.1/couchdb-views.xml new file mode 100644 index 000000000..2056d2995 --- /dev/null +++ b/share/docs/couchdb-manual-1.1/couchdb-views.xml @@ -0,0 +1,15 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-single-views"> + + <title>Views</title> + + <para> + + </para> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-auth.xml b/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-auth.xml new file mode 100644 index 000000000..3c4762b7d --- /dev/null +++ b/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-auth.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-api-auth"> + + <title>CouchDB API Server Authentication Methods</title> + + <para> + The CouchDB Authentication methods provide an interface for + obtaining session and authorization data. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-api-auth-summary"><title>Authentication API Calls</title><tgroup cols="3"><colspec colname="method"/><colspec colname="path"/><colspec colname="desc"/><thead><row><entry>Method</entry><entry>Path</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>GET</literal></entry><entry><literal>/_oauth/access_token</literal></entry><entry><link linkend="couchdb-api-auth_access-token_get"> + TBC + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/_oauth/authorize</literal></entry><entry><link linkend="couchdb-api-auth_authorize_get"> + TBC + </link></entry></row><row><entry><literal>POST</literal></entry><entry><literal>/_oauth/authorize</literal></entry><entry><link linkend="couchdb-api-auth_authorize_post"> + TBC + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/_oauth/request_token</literal></entry><entry><link linkend="couchdb-api-auth_authorize_get"> + TBC + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/_session</literal></entry><entry><link linkend="couchdb-api-auth_session_get"> + Returns cookie based login user information + </link></entry></row><row><entry><literal>POST</literal></entry><entry><literal>/_session</literal></entry><entry><link linkend="couchdb-api-auth_session_post"> + Do cookie based user login + </link></entry></row><row><entry><literal>DELETE</literal></entry><entry><literal>/_session</literal></entry><entry><link linkend="couchdb-api-auth_session_delete"> + Logout cookie based user + </link></entry></row></tbody></tgroup></table> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-config.xml b/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-config.xml new file mode 100644 index 000000000..d7af03370 --- /dev/null +++ b/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-config.xml @@ -0,0 +1,348 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-api-config"> + + <title>CouchDB API Server Configuration Methods</title> + + <para> + The CouchDB API Server Configuration Methods provide an interface to + query and update the various configuration values within a running + CouchDB instance. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-api-config-summary"><title>Configuration API Calls</title><tgroup cols="3"><colspec colname="method"/><colspec colname="path"/><colspec colname="desc"/><thead><row><entry>Method</entry><entry>Path</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>GET</literal></entry><entry><literal>/_config</literal></entry><entry><link linkend="couchdb-api-config_config_get"> + Obtain a list of the entire server configuration + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/_config/section</literal></entry><entry><link linkend="couchdb-api-config_config-section_get"> + Get all the configuration values for the specified section + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/_config/section/key</literal></entry><entry><link linkend="couchdb-api-config_config-section-key_get"> + Get a specific section/configuration value + </link></entry></row><row><entry><literal>PUT</literal></entry><entry><literal>/_config/section/key</literal></entry><entry><link linkend="couchdb-api-config_config-section-key_put"> + Set the specified configuration value + </link></entry></row><row><entry><literal>DELETE</literal></entry><entry><literal>/_config/section/key</literal></entry><entry><link linkend="couchdb-api-config_config-section-key_delete"> + Delete the current setting + </link></entry></row></tbody></tgroup></table> + + <section id="couchdb-api-config_config_get"> + + <title><literal>GET /_config</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /_config</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /_config</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Returns a structure configuration name and value pairs, + organized by section + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Returns the entire CouchDB server configuration as a JSON + structure. The structure is organized by different configuration + sections, with individual values. + </para> + + <para> + For example, to get the configuration for a server: + </para> + +<programlisting> +GET http://couchdb:5984/_config +Accept: application/json +</programlisting> + + <para> + The response is the JSON structure: + </para> + +<programlisting> +<![CDATA[{ + "query_server_config" : { + "reduce_limit" : "true" + }, + "couchdb" : { + "os_process_timeout" : "5000", + "max_attachment_chunk_size" : "4294967296", + "max_document_size" : "4294967296", + "uri_file" : "/var/lib/couchdb/couch.uri", + "max_dbs_open" : "100", + "view_index_dir" : "/var/lib/couchdb", + "util_driver_dir" : "/usr/lib64/couchdb/erlang/lib/couch-1.0.1/priv/lib", + "database_dir" : "/var/lib/couchdb", + "delayed_commits" : "true" + }, + "attachments" : { + "compressible_types" : "text/*, application/javascript, application/json, application/xml", + "compression_level" : "8" + }, + "uuids" : { + "algorithm" : "utc_random" + }, + "daemons" : { + "view_manager" : "{couch_view, start_link, []}", + "auth_cache" : "{couch_auth_cache, start_link, []}", + "uuids" : "{couch_uuids, start, []}", + "stats_aggregator" : "{couch_stats_aggregator, start, []}", + "query_servers" : "{couch_query_servers, start_link, []}", + "httpd" : "{couch_httpd, start_link, []}", + "stats_collector" : "{couch_stats_collector, start, []}", + "db_update_notifier" : "{couch_db_update_notifier_sup, start_link, []}", + "external_manager" : "{couch_external_manager, start_link, []}" + }, + "stats" : { + "samples" : "[0, 60, 300, 900]", + "rate" : "1000" + }, + "httpd" : { + "vhost_global_handlers" : "_utils, _uuids, _session, _oauth, _users", + "secure_rewrites" : "true", + "authentication_handlers" : "{couch_httpd_oauth, oauth_authentication_handler}, + {couch_httpd_auth, cookie_authentication_handler}, + {couch_httpd_auth, default_authentication_handler}", + "port" : "5984", + "default_handler" : "{couch_httpd_db, handle_request}", + "allow_jsonp" : "false", + "bind_address" : "192.168.0.2", + "max_connections" : "2048" + }, + "query_servers" : { + "javascript" : "/usr/bin/couchjs /usr/share/couchdb/server/main.js" + }, + "couch_httpd_auth" : { + "authentication_db" : "_users", + "require_valid_user" : "false", + "authentication_redirect" : "/_utils/session.html", + "timeout" : "600", + "auth_cache_size" : "50" + }, + "httpd_db_handlers" : { + "_design" : "{couch_httpd_db, handle_design_req}", + "_compact" : "{couch_httpd_db, handle_compact_req}", + "_view_cleanup" : "{couch_httpd_db, handle_view_cleanup_req}", + "_temp_view" : "{couch_httpd_view, handle_temp_view_req}", + "_changes" : "{couch_httpd_db, handle_changes_req}" + }, + "replicator" : { + "max_http_sessions" : "10", + "max_http_pipeline_size" : "10" + }, + "log" : { + "include_sasl" : "true", + "level" : "info", + "file" : "/var/log/couchdb/couch.log" + }, + "httpd_design_handlers" : { + "_update" : "{couch_httpd_show, handle_doc_update_req}", + "_show" : "{couch_httpd_show, handle_doc_show_req}", + "_info" : "{couch_httpd_db, handle_design_info_req}", + "_list" : "{couch_httpd_show, handle_view_list_req}", + "_view" : "{couch_httpd_view, handle_view_req}", + "_rewrite" : "{couch_httpd_rewrite, handle_rewrite_req}" + }, + "httpd_global_handlers" : { + "_replicate" : "{couch_httpd_misc_handlers, handle_replicate_req}", + "/" : "{couch_httpd_misc_handlers, handle_welcome_req, <<\"Welcome\">>}", + "_config" : "{couch_httpd_misc_handlers, handle_config_req}", + "_utils" : "{couch_httpd_misc_handlers, handle_utils_dir_req, \"/usr/share/couchdb/www\"}", + "_active_tasks" : "{couch_httpd_misc_handlers, handle_task_status_req}", + "_session" : "{couch_httpd_auth, handle_session_req}", + "_log" : "{couch_httpd_misc_handlers, handle_log_req}", + "favicon.ico" : "{couch_httpd_misc_handlers, handle_favicon_req, \"/usr/share/couchdb/www\"}", + "_all_dbs" : "{couch_httpd_misc_handlers, handle_all_dbs_req}", + "_oauth" : "{couch_httpd_oauth, handle_oauth_req}", + "_restart" : "{couch_httpd_misc_handlers, handle_restart_req}", + "_uuids" : "{couch_httpd_misc_handlers, handle_uuids_req}", + "_stats" : "{couch_httpd_stats_handlers, handle_stats_req}" + } +}]]> + </programlisting> + + </section> + + <section id="couchdb-api-config_config-section_get"> + + <title><literal>GET /_config/section</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /_config/section</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /_config/section</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + All the configuration values within a specified section + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Gets the configuration structure for a single section. For + example, to retrieve the CouchDB configuration section values: + </para> + +<programlisting> +GET http://couchdb:5984/_config/couchdb +Accept: application/json +</programlisting> + + <para> + The returned JSON contains just the configuration values for this + section: + </para> + +<programlisting> +{ + "os_process_timeout" : "5000", + "max_attachment_chunk_size" : "4294967296", + "max_document_size" : "4294967296", + "uri_file" : "/var/lib/couchdb/couch.uri", + "max_dbs_open" : "100", + "view_index_dir" : "/var/lib/couchdb", + "util_driver_dir" : "/usr/lib64/couchdb/erlang/lib/couch-1.0.1/priv/lib", + "database_dir" : "/var/lib/couchdb", + "delayed_commits" : "true" +} +</programlisting> + + </section> + + <section id="couchdb-api-config_config-section-key_get"> + + <title><literal>GET /_config/section/key</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /_config/section/key</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /_config/section/key</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Value of the specified key/section + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Gets a single configuration value from within a specific + configuration section. For example, to obtain the current log + level: + </para> + +<programlisting> +GET http://couchdb:5984/_config/log/level +Accept: application/json +</programlisting> + + <para> + Returns the string of the log level: + </para> + +<programlisting> +"info" +</programlisting> + + <note> + <para> + The returned value will be the JSON of the value, which may be a + string or numeric value, or an array or object. Some client + environments may not parse simple strings or numeric values as + valid JSON. + </para> + </note> + + </section> + + <section id="couchdb-api-config_config-section-key_put"> + + <title><literal>PUT /_config/section/key</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API PUT /_config/section/key</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>PUT /_config/section/key</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + Value structure + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Previous value + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Configuration option updated successfully + </entry></row><row><entry>500</entry><entry namest="info" nameend="addinfo"> + Error setting configuration + </entry></row></tbody></tgroup></informaltable> + + <para> + Updates a configuration value. The new value should be supplied in + the request body in the corresponding JSON format. For example, if + you are setting a string value, you must supply a valid JSON + string. + </para> + + <para> + For example, to set the function used to generate UUIDs by the + <literal>GET /_uuids</literal> API call to use the + <literal>utc_random</literal> generator: + </para> + +<programlisting> +PUT http://couchdb:5984/_config/uuids/algorithm +Content-Type: application/json + +"utc_random" +</programlisting> + + <para> + The return value will be empty, with the response code indicating + the success or failure of the configuration setting. + </para> + + </section> + + <section id="couchdb-api-config_config-section-key_delete"> + + <title><literal>DELETE /_config/section/key</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API DELETE /_config/section/key</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>DELETE /_config/section/key</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Previous value + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>rev</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Current revision of the document for validation + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal>If-Match</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry>Current revision of the document for validation</entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>409</entry><entry namest="info" nameend="addinfo"> + Supplied revision is incorrect or missing + </entry></row></tbody></tgroup></informaltable> + + <para> + Deletes a configuration value. The returned JSON will be the value + of the configuration parameter before it was deleted. For example, + to delete the UUID parameter: + </para> + +<programlisting> +DELETE http://couchdb:5984/_config/uuids/algorithm +Content-Type: application/json +</programlisting> + + <para> + The returned value is the last configured UUID function: + </para> + +<programlisting> +"random" +</programlisting> + + </section> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-db.xml b/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-db.xml new file mode 100644 index 000000000..16fde4f85 --- /dev/null +++ b/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-db.xml @@ -0,0 +1,1937 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-api-db"> + + <title>CouchDB API Server Database Methods</title> + + <para> + The Database methods provide an interface to an entire database + withing CouchDB. These are database, rather than document, level + requests. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-db-summary"><title>Database API Calls</title><tgroup cols="3"><colspec colname="method"/><colspec colname="path"/><colspec colname="desc"/><thead><row><entry>Method</entry><entry>Path</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>GET</literal></entry><entry><literal>/db</literal></entry><entry><link linkend="couchdb-api-db_db_get"> + Returns database information + </link></entry></row><row><entry><literal>PUT</literal></entry><entry><literal>/db</literal></entry><entry><link linkend="couchdb-api-db_db_put"> + Create a new database + </link></entry></row><row><entry><literal>DELETE</literal></entry><entry><literal>/db</literal></entry><entry><link linkend="couchdb-api-db_db_delete"> + Delete an existing database + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/db/_all_docs</literal></entry><entry><link linkend="couchdb-api-db_db-all-docs_get"> + Returns a built-in view of all documents in this database + </link></entry></row><row><entry><literal>POST</literal></entry><entry><literal>/db/_all_docs</literal></entry><entry><link linkend="couchdb-api-db_db-all-docs_post"> + Returns certain rows from the built-in view of all documents + </link></entry></row><row><entry><literal>POST</literal></entry><entry><literal>/db/_bulk_docs</literal></entry><entry><link linkend="couchdb-api-db_db-bulk-docs_post"> + Insert multiple documents in to the database in a single request + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/db/_changes</literal></entry><entry><link linkend="couchdb-api-db_db-changes_get"> + Returns changes for the given database + </link></entry></row><row><entry><literal>POST</literal></entry><entry><literal>/db/_compact</literal></entry><entry><link linkend="couchdb-api-db_db-compact_post"> + Starts a compaction for the database + </link></entry></row><row><entry><literal>POST</literal></entry><entry><literal>/db/_compact/design-doc</literal></entry><entry><link linkend="couchdb-api-db_db-compact-design-doc_post"> + Starts a compaction for all the views in the selected design + document + </link></entry></row><row><entry><literal>POST</literal></entry><entry><literal>/db/_ensure_full_commit</literal></entry><entry><link linkend="couchdb-api-db_db-ensure-full-commit_post"> + Makes sure all uncommitted changes are written and synchronized + to the disk + </link></entry></row><row><entry><literal>POST</literal></entry><entry><literal>/db/_missing_revs</literal></entry><entry><link linkend="couchdb-api-db_db-missing-revs_post"> + Given a list of document revisions, returns the document + revisions that do not exist in the database + </link></entry></row><row><entry><literal>POST</literal></entry><entry><literal>/db/_purge</literal></entry><entry><link linkend="couchdb-api-db_db-purge_post"> + Purge some historical documents entirely from database history + </link></entry></row><row><entry><literal>POST</literal></entry><entry><literal>/db/_revs_diff</literal></entry><entry><link linkend="couchdb-api-db_db-revs-diff_post"> + Given a list of document revisions, returns differences between + the given revisions and ones that are in the database + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/db/_revs_limit</literal></entry><entry><link linkend="couchdb-api-db_db-revs-limit_get"> + Gets the limit of historical revisions to store for a single + document in the database + </link></entry></row><row><entry><literal>PUT</literal></entry><entry><literal>/db/_revs_limit</literal></entry><entry><link linkend="couchdb-api-db_db-revs-limit_put"> + Sets the limit of historical revisions to store for a single + document in the database + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/db/_security</literal></entry><entry><link linkend="couchdb-api-db_db-security_get"> + Returns the special security object for the database + </link></entry></row><row><entry><literal>PUT</literal></entry><entry><literal>/db/_security</literal></entry><entry><link linkend="couchdb-api-db_db-security_put"> + Sets the special security object for the database + </link></entry></row><row><entry><literal>POST</literal></entry><entry><literal>/db/_temp_view</literal></entry><entry><link linkend="couchdb-api-db_db-temp-view_post"> + Execute a given view function for all documents and return the + result + </link></entry></row><row><entry><literal>POST</literal></entry><entry><literal>/db/_view_cleanup</literal></entry><entry><link linkend="couchdb-api-db_db-view-cleanup_post"> + Removes view files that are not used by any design document + </link></entry></row></tbody></tgroup></table> + + <para> + For all the database methods, the database name within the URL path + should be the database name that you wish to perform the operation + on. For example, to obtain the meta information for the database + <literal>recipes</literal>, you would use the HTTP request: + </para> + +<programlisting> +GET /recipes +</programlisting> + + <para> + For clarity, the form below is used in the URL paths: + </para> + +<programlisting> +GET /db +</programlisting> + + <para> + Where <literal>db</literal> is the name of any database. + </para> + + <section id="couchdb-api-db_db_get"> + + <title><literal>GET /db</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /db</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /db</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Information about the database in JSON format + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>404</entry><entry namest="info" nameend="addinfo"> + The requested content could not be found. The returned content + will include further information, as a JSON object, if available. + </entry></row></tbody></tgroup></informaltable> + + <para> + Gets information about the specified database. For example, to + retrieve the information for the database + <literal>recipe</literal>: + </para> + +<programlisting role="httprequest"> +GET http://couchdb:5984/recipes +Accept: application/json +</programlisting> + + <para> + The JSON response contains meta information about the database. A + sample of the JSON returned for an empty database is provided + below: + </para> + +<programlisting role="httpresponse"> +{ + "compact_running" : false, + "committed_update_seq" : 375048, + "disk_format_version" : 5, + "disk_size" : 33153123, + "doc_count" : 18386, + "doc_del_count" : 0, + "db_name" : "recipes", + "instance_start_time" : "1290700340925570", + "purge_seq" : 10, + "update_seq" : 375048 +} + </programlisting> + + <para> + The elements of the returned structure are shown in the table + below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-db-json-db-info" class="jsonstructure"><title> + CouchDB database information object + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>committed_update_seq</literal> </entry><entry> + The number of committed update. + </entry></row><row><entry ><literal>compact_running</literal> </entry><entry> + Set to true if the database compaction routine is operating on + this database. + </entry></row><row><entry ><literal>db_name</literal> </entry><entry> + The name of the database. + </entry></row><row><entry ><literal>disk_format_version</literal> </entry><entry> + The version of the physical format used for the data when it is + stored on disk. + </entry></row><row><entry ><literal>disk_size</literal> </entry><entry> + Size in bytes of the data as stored on the disk. Views indexes + are not included in the calculation. + </entry></row><row><entry ><literal>doc_count</literal> </entry><entry> + A count of the documents in the specified database. + </entry></row><row><entry ><literal>doc_del_count</literal> </entry><entry> + Number of deleted documents + </entry></row><row><entry ><literal>instance_start_time</literal> </entry><entry> + Timestamp of when the database was created, expressed in + milliseconds since the epoch. + </entry></row><row><entry ><literal>purge_seq</literal> </entry><entry> + The number of purge operations on the database. + </entry></row><row><entry ><literal>update_seq</literal> </entry><entry> + The current number of updates to the database. + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-api-db_db_put"> + + <title><literal>PUT /db</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API PUT /db</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>PUT /db</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON success statement + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>400</entry><entry namest="info" nameend="addinfo"> + Invalid database name + </entry></row><row><entry>412</entry><entry namest="info" nameend="addinfo"> + Database already exists + </entry></row></tbody></tgroup></informaltable> + + <para> + Creates a new database. The database name must be composed of one + or more of the following characters: + </para> + + <itemizedlist> + + <listitem> + <para> + Lowercase characters (<literal>a-z</literal>) + </para> + </listitem> + + <listitem> + <para> + Name must begin with a lowercase letter + </para> + </listitem> + + <listitem> + <para> + Digits (<literal>0-9</literal>) + </para> + </listitem> + + <listitem> + <para> + Any of the characters <literal>_</literal>, + <literal>$</literal>, <literal>(</literal>, + <literal>)</literal>, <literal>+</literal>, + <literal>-</literal>, and <literal>/</literal>. + </para> + </listitem> + + </itemizedlist> + + <para> + Trying to create a database that does not meet these requirements + will return an error quoting these restrictions. + </para> + + <para> + To create the database <literal>recipes</literal>: + </para> + +<programlisting> +PUT http://couchdb:5984/recipes +Content-Type: application/json +</programlisting> + + <para> + The returned content contains the JSON status: + </para> + +<programlisting> +{ + "ok" : true +} +</programlisting> + + <para> + Anything should be treated as an error, and the problem should be + taken form the HTTP response code. + </para> + + </section> + + <section id="couchdb-api-db_db_delete"> + + <title><literal>DELETE /db</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API DELETE /db</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>DELETE /db</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON success statement + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Database has been deleted + </entry></row><row><entry>404</entry><entry namest="info" nameend="addinfo"> + The requested content could not be found. The returned content + will include further information, as a JSON object, if available. + </entry></row></tbody></tgroup></informaltable> + + <para> + Deletes the specified database, and all the documents and + attachments contained within it. + </para> + + <para> + To delete the database <literal>recipes</literal> you would send + the request: + </para> + +<programlisting> +DELETE http://couchdb:5984/recipes +Content-Type: application/json +</programlisting> + + <para> + If successful, the returned JSON will indicate success + </para> + +<programlisting> +{ + "ok" : true +} +</programlisting> + + </section> + + <section id="couchdb-api-db_db-changes_get"> + + <title><literal>GET /db/_changes</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_changes</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /db/_changes</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the changes to the database + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>doc_ids</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specify the list of documents IDs to be filtered + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>json</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>none</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>feed</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Type of feed + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>normal</entry></row><row><entry></entry><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry></entry><entry><literal>continuous</literal></entry><entry>Continuous (non-polling) mode</entry></row><row><entry></entry><entry><literal>longpoll</literal></entry><entry>Long polling mode</entry></row><row><entry></entry><entry><literal>normal</literal></entry><entry>Normal mode</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>filter</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Filter function from a design document to get updates + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>none</entry></row><row><entry></entry><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>heartbeat</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Period after which an empty line is sent during longpoll or + continuous + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>60000</entry></row><row><entry></entry><entry><emphasis role="bold">Quantity</emphasis></entry><entry>milliseconds</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>include_docs</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Include the document with the result + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>limit</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Maximum number of rows rows to return + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>none</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>since</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Start the results from changes immediately after the + specified sequence number + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>0</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>timeout</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Maximum period to wait before the response is sent + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>60000</entry></row><row><entry></entry><entry><emphasis role="bold">Quantity</emphasis></entry><entry>milliseconds</entry></row></tbody></tgroup></informaltable> + + <para> + Obtains a list of the changes made to the database. This can be + used to monitor for update and modifications to the database for + post processing or synchronization. There are three different + types of supported changes feeds, poll, longpoll, and continuous. + All requests are poll requests by default. You can select any feed + type explicitly using the <literal>feed</literal> query argument. + </para> + + <para> + <itemizedlist> + + <listitem> + <para> + <emphasis role="bold">Poll</emphasis> + </para> + + <para> + With polling you can request the changes that have occured + since a specific sequence number. This returns the JSON + structure containing the changed document information. When + you perform a poll change request, only the changes since + the specific sequence number are returned. For example, the + query + </para> + +<programlisting> +DELETE http://couchdb:5984/recipes/_changes +Content-Type: application/json +</programlisting> + + <para> + Will get all of the changes in the database. You can request + a starting point using the <literal>since</literal> query + argument and specifying the sequence number. You will need + to record the latest sequence number in your client and then + use this when making another request as the new value to the + <literal>since</literal> parameter. + </para> + </listitem> + + <listitem> + <para> + <emphasis role="bold">Longpoll</emphasis> + </para> + + <para> + With long polling the request to the server will remain open + until a change is made on the database, when the changes + will be reported, and then the connection will close. The + long poll is useful when you want to monitor for changes for + a specific purpose without wanting to monitoring + continuously for changes. + </para> + + <para> + Because the wait for a change can be significant you can set + a timeout before the connection is automatically closed (the + <literal>timeout</literal> argument). You can also set a + heartbeat interval (using the <literal>heartbeat</literal> + query argument), which sends a newline to keep the + connection open. + </para> + </listitem> + + <listitem> + <para> + <emphasis role="bold">Continuous</emphasis> + </para> + + <para> + Continuous sends all new changes back to the client + immediately, without closing the connection. In continuous + mode the format of the changes is slightly different to + accommodate the continuous nature while ensuring that the + JSON output is still valid for each change notification. + </para> + + <para> + As with the longpoll feed type you can set both the timeout + and heartbeat intervals to ensure that the connection is + kept open for new changesand updates. + </para> + </listitem> + + </itemizedlist> + </para> + + <para> + The return structure for <literal>normal</literal> and + <literal>longpoll</literal> modes is a JSON array of changes + objects, and the last update sequence number. The structure is + described in the following table. + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-db_db-json-changes" class="jsonstructure"><title> + Changes information for a database + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>last_seq</literal> </entry><entry> + Last change sequence number + </entry></row><row><entry ><literal>results</literal> <literal>[array]</literal> </entry><entry> + Changes made to a database + </entry></row><row><entry > <literal>changes</literal> <literal>[array]</literal> </entry><entry> + List of changes, field-by-field, for this document + </entry></row><row><entry > <literal>id</literal> </entry><entry> + Document ID + </entry></row><row><entry > <literal>seq</literal> </entry><entry> + Update sequence number + </entry></row></tbody></tgroup></table> + + <para> + The return format for <literal>continuous</literal> mode the + server sends a CRLF (carriage-return, linefeed) delimited line for + each change. Each line contains the + <link linkend="table-couchdb-api-db_db-json-changes">JSON + object</link>. + </para> + + <para> + You can also request the full contents of each document change + (instead of just the change notification) by using the + <literal>include_docs</literal> parameter. + </para> + + <section id="couchdb-api-db_db-changes_get-filters"> + + <title>Filtering</title> + + <para> + You can filter the contents of the changes feed in a number of + ways. The most basic way is to specify one or more document IDs + to the query. This causes the returned structure value to only + contain changes for the specified IDs. Note that the value of + this query argument should be a JSON formatted array. + </para> + + <para> + You can also filter the <literal>_changes</literal> feed by + defining a filter function within a design document. The + specification for the filter is the same as for replication + filters. You specify the name of the filter function to the + <literal>filter</literal> parameter, specifying the design + document name and filter name. For example: + </para> + +<programlisting> +GET /db/_changes?filter=design_doc/filtername +</programlisting> + + <para> + The <literal>_changes</literal> feed can be used to watch + changes to specific document ID's or the list of + <literal>_design</literal> documents in a database. If the + <literal>filters</literal> parameter is set to + <literal>_doc_ids</literal> a list of doc IDs can be passed in + the <option>doc_ids</option> parameter as a JSON array. + </para> + + <para> + For more information, see + <xref linkend="couchdb-single-changes-filters"/>. + </para> + + </section> + + </section> + + <section id="couchdb-api-db_db-compact_post"> + + <title><literal>POST /db/_compact</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_compact</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>POST /db/_compact</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON success statement + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>202</entry><entry namest="info" nameend="addinfo"> + Compaction request has been accepted + </entry></row><row><entry>404</entry><entry namest="info" nameend="addinfo"> + The requested content could not be found. The returned content + will include further information, as a JSON object, if available. + </entry></row></tbody></tgroup></informaltable> + + <para> + Request compaction of the specified database. Compaction + compresses the disk database file by performing the following + operations: + </para> + + <itemizedlist> + + <listitem> + <para> + Writes a new version of the database file, removing any unused + sections from the new version during write. Because a new file + is temporary created for this purpose, you will need twice the + current storage space of the specified database in order for + the compaction routine to complete. + </para> + </listitem> + + <listitem> + <para> + Removes old revisions of documents from the database, up to + the per-database limit specified by the + <literal>_revs_limit</literal> database parameter. See + <xref linkend="couchdb-api-db_db_get"/> . + </para> + </listitem> + + </itemizedlist> + + <para> + Compaction can only be requested on an individual database; you + cannot compact all the databases for a CouchDB instance. The + compaction process runs as a background process. + </para> + + <para> + You can determine if the compaction process is operating on a + database by obtaining the database meta information, the + <literal>compact_running</literal> value of the returned database + structure will be set to true. See + <xref linkend="couchdb-api-db_db_get"/> . + </para> + + <para> + You can also obtain a list of running processes to determine + whether compaction is currently running. See + <xref linkend="couchdb-api-misc_active-tasks_get"/>. + </para> + + </section> + + <section id="couchdb-api-db_db-compact-design-doc_post"> + + <title><literal>POST /db/_compact/design-doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_compact/design-doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>POST /db/_compact/design-doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON success statement + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">yes</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>202</entry><entry namest="info" nameend="addinfo"> + Compaction request has been accepted + </entry></row><row><entry>404</entry><entry namest="info" nameend="addinfo"> + The requested content could not be found. The returned content + will include further information, as a JSON object, if available. + </entry></row></tbody></tgroup></informaltable> + + <para> + Compacts the view indexes associated with the specified design + document. You can use this in place of the full database + compaction if you know a specific set of view indexes have been + affected by a recent database change. + </para> + + <para> + For example, to compact the views associated with the + <literal>recipes</literal> design document: + </para> + +<programlisting> +POST http://couchdb:5984/recipes/_compact/recipes +Content-Type: application/json +</programlisting> + + <para> + CouchDB will immediately return with a status indicating that the + compaction request has been received (HTTP status code 202): + </para> + +<programlisting> +{ + "ok" : true +} + </programlisting> + + </section> + + <section id="couchdb-api-db_db-view-cleanup_post"> + + <title><literal>POST /db/_view_cleanup</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_view_cleanup</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>POST /db/_view_cleanup</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON success statement + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">yes</entry></row></tbody></tgroup></informaltable> + + <para> + Cleans up the cached view output on disk for a given view. For + example: + </para> + +<programlisting> +POST http://couchdb:5984/recipes/_view_cleanup +Content-Type: application/json +</programlisting> + + <para> + If the request is successful, a basic status message us returned: + </para> + +<programlisting> +{ + "ok" : true +} + </programlisting> + + </section> + + <section id="couchdb-api-db_db-ensure-full-commit_post"> + + <title><literal>POST /db/_ensure_full_commit</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_ensure_full_commit</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>POST /db/_ensure_full_commit</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON success statement + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Commit completed successfully + </entry></row><row><entry>404</entry><entry namest="info" nameend="addinfo"> + The requested content could not be found. The returned content + will include further information, as a JSON object, if available. + </entry></row></tbody></tgroup></informaltable> + + <para> + Commits any recent changes to the specified database to disk. You + should call this if you want to ensure that recent changes have + been written. For example, to commit all the changes to disk for + the database <literal>recipes</literal> you would use: + </para> + +<programlisting> +POST http://couchdb:5984/recipes/_ensure_full_commit +Content-Type: application/json +</programlisting> + + <para> + This returns a status message, containing the success message and + the timestamp for when the CouchDB instance was started: + </para> + +<programlisting> +{ + "ok" : true, + "instance_start_time" : "1288186189373361" +} +</programlisting> + + + + </section> + + <section id="couchdb-api-db_db-bulk-docs_post"> + + <title><literal>POST /db/_bulk_docs</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_bulk_docs</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>POST /db/_bulk_docs</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the docs and updates to be applied + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of updated documents + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>201</entry><entry namest="info" nameend="addinfo"> + Document(s) have been created or updated + </entry></row></tbody></tgroup></informaltable> + + <para> + The bulk document API allows you to create and update multiple + documents at the same time within a single request. The basic + operation is similar to creating or updating a single document, + except that you batch the document structure and information and . + When creating new documents the document ID is optional. For + updating existing documents, you must provide the document ID, + revision information, and new document values. + </para> + + <para> + For both inserts and updates the basic structure of the JSON is + the same: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-db_db-bulk-docs-json" class="jsonstructure"><title> + Bulk Documents + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>all_or_nothing</literal> (optional) </entry><entry> + Sets the database commit mode to use all-or-nothing semantics + </entry></row><row><entry ><literal>docs</literal> <literal>[array]</literal> </entry><entry> + Bulk Documents Document + </entry></row><row><entry > <literal>_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry > <literal>_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row><row><entry > <literal>_deleted</literal> (optional) </entry><entry> + Whether the document should be deleted + </entry></row></tbody></tgroup></table> + + <section id="couchdb-api-db_db-bulk-docs_post-insert"> + + <title>Inserting Documents in Bulk</title> + + <para> + To insert documents in bulk into a database you need to supply a + JSON structure with the array of documents that you want to add + to the database. Using this method you can either include a + document ID, or allow the document ID to be automatically + generated. + </para> + + <para> + For example, the following inserts three new documents, two with + the supplied document IDs, and one which will have a document ID + generated: + </para> + +<programlisting> +{ + "docs" : [ + { + "_id" : "FishStew", + "servings" : 4, + "subtitle" : "Delicious with fresh bread", + "title" : "Fish Stew" + }, + { + "_id" : "LambStew", + "servings" : 6, + "subtitle" : "Delicious with scone topping", + "title" : "Lamb Stew" + }, + { + "servings" : 8, + "subtitle" : "Delicious with suet dumplings", + "title" : "Beef Stew" + }, + ] +} + </programlisting> + + <para> + The return type from a bulk insertion will be 201, with the + content of the returned structure indicating specific success or + otherwise messages on a per-document basis. + </para> + + <para> + The return structure from the example above contains a list of + the documents created, here with the combination and their + revision IDs: + </para> + +<programlisting> +POST http://couchdb:5984/recipes/_bulk_docs +Content-Type: application/json + +[ + { + "id" : "FishStew", + "rev" : "1-9c65296036141e575d32ba9c034dd3ee", + }, + { + "id" : "LambStew", + "rev" : "1-34c318924a8f327223eed702ddfdc66d", + }, + { + "id" : "7f7638c86173eb440b8890839ff35433", + "rev" : "1-857c7cbeb6c8dd1dd34a0c73e8da3c44", + } +] + </programlisting> + + <para> + The content and structure of the returned JSON will depend on + the transaction semantics being used for the bulk update; see + <xref + linkend="couchdb-api-db_db-bulk-docs_post-commit"/> + for more information. Conflicts and validation errors when + updating documents in bulk must be handled separately; see + <xref + linkend="couchdb-api-db_db-bulk-docs_post-errors"/>. + </para> + + </section> + + <section id="couchdb-api-db_db-bulk-docs_post-update"> + + <title>Updating Documents in Bulk</title> + + <para> + The bulk document update procedure is similar to the insertion + procedure, except that you must specify the document ID and + current revision for every document in the bulk update JSON + string. + </para> + + <para> + For example, you could send the following request: + </para> + +<programlisting> +POST http://couchdb:5984/recipes/_bulk_docs +Content-Type: application/json + +{ + "docs" : [ + { + "_id" : "FishStew", + "_rev" : "1-9c65296036141e575d32ba9c034dd3ee", + "servings" : 4, + "subtitle" : "Delicious with freshly baked bread", + "title" : "Fish Stew" + }, + { + "_id" : "LambStew", + "_rev" : "1-34c318924a8f327223eed702ddfdc66d", + "servings" : 6, + "subtitle" : "Serve with a wholemeal scone topping", + "title" : "Lamb Stew" + }, + { + "_id" : "7f7638c86173eb440b8890839ff35433" + "_rev" : "1-857c7cbeb6c8dd1dd34a0c73e8da3c44", + "servings" : 8, + "subtitle" : "Hand-made dumplings make a great accompaniment", + "title" : "Beef Stew" + } + ] +} +</programlisting> + + <para> + The return structure is the JSON of the updated documents, with + the new revision and ID information: + </para> + +<programlisting> +[ + { + "id" : "FishStew", + "rev" : "2-e7af4c4e9981d960ecf78605d79b06d1" + }, + { + "id" : "LambStew", + "rev" : "2-0786321986194c92dd3b57dfbfc741ce" + }, + { + "id" : "7f7638c86173eb440b8890839ff35433", + "rev" : "2-bdd3bf3563bee516b96885a66c743f8e" + } +] +</programlisting> + + <para> + You can optionally delete documents during a bulk update by + adding the <literal>_deleted</literal> field with a value of + <literal>true</literal> to each docment ID/revision combination + within the submitted JSON structure. + </para> + + <para> + The return type from a bulk insertion will be 201, with the + content of the returned structure indicating specific success or + otherwise messages on a per-document basis. + </para> + + <para> + The content and structure of the returned JSON will depend on + the transaction semantics being used for the bulk update; see + <xref + linkend="couchdb-api-db_db-bulk-docs_post-commit"/> + for more information. Conflicts and validation errors when + updating documents in bulk must be handled separately; see + <xref + linkend="couchdb-api-db_db-bulk-docs_post-errors"/>. + </para> + + </section> + + <section id="couchdb-api-db_db-bulk-docs_post-commit"> + + <title>Bulk Documents Transaction Semantics</title> + + <para> + CouchDB supports two different modes for updating (or inserting) + documents using the bulk documentation system. Each mode affects + both the state of the documents in the event of system failure, + and the level of conflict checking performed on each document. + The two modes are: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal>non-atomic</literal> + </para> + + <para> + The default mode is non-atomic, that is, CouchDB will only + guarantee that some of the documents will be saved when you + send the request. The response will contain the list of + documents successfully inserted or updated during the + process. In the event of a crash, some of the documents may + have been successfully saved, and some will have been lost. + </para> + + <para> + In this mode, the response structure will indicate whether + the document was updated by supplying the new + <literal>_rev</literal> parameter indicating a new document + revision was created. If the update failed, then you will + get an <literal>error</literal> of type + <literal>conflict</literal>. For example: + </para> + +<programlisting> +[ + { + "id" : "FishStew", + "error" : "conflict", + "reason" : "Document update conflict." + }, + { + "id" : "LambStew", + "error" : "conflict", + "reason" : "Document update conflict." + }, + { + "id" : "7f7638c86173eb440b8890839ff35433", + "error" : "conflict", + "reason" : "Document update conflict." + } +] + </programlisting> + + <para> + In this case no new revision has been created and you will + need to submit the document update, with the correct + revision tag, to update the document. + </para> + </listitem> + + <listitem> + <para> + <literal>all-or-nothing</literal> + </para> + + <para> + In all-or-nothing mode, either all documents are written to + the database, or no documents are written to the database, + in the event of a system failure during commit. + </para> + + <para> + In addition, the per-document conflict checking is not + performed. Instead a new revision of the document is + created, even if the new revision is in conflict with the + current revision in the database. The returned structure + contains the list of documents with new revisions: + </para> + +<programlisting> +[ + { + "id" : "FishStew", + "rev" : "2-e7af4c4e9981d960ecf78605d79b06d1" + }, + { + "id" : "LambStew", + "rev" : "2-0786321986194c92dd3b57dfbfc741ce" + }, + { + "id" : "7f7638c86173eb440b8890839ff35433", + "rev" : "2-bdd3bf3563bee516b96885a66c743f8e" + } +] +</programlisting> + + <para> + When updating documents using this mode the revision of a + document included in views will be arbitrary. You can check + the conflict status for a document by using the + <literal>conflicts=true</literal> query argument when + accessing the view. Conflicts should be handled individually + to ensure the consistency of your database. + </para> + + + + <para> + To use this mode, you must include the + <literal>all_or_nothing</literal> field (set to true) within + the main body of the JSON of the request. + </para> + </listitem> + + </itemizedlist> + + <para> + The effects of different database operations on the different + modes are summarized in the table below: + </para> + + <table id="table-couchdb-api-db_db-bulk-docs_post-commit"> + <title>Conflicts on Bulk Inserts</title> + <tgroup cols="4"> + <thead> + <row> + <entry> + Transaction Mode + </entry> + <entry> + Transaction + </entry> + <entry> + Cause + </entry> + <entry> + Resolution + </entry> + </row> + </thead> + <tbody> + <row> + <entry> + Non-atomic + </entry> + <entry> + Insert + </entry> + <entry> + Requested document ID already exists + </entry> + <entry> + Resubmit with different document ID, or update the + existing document + </entry> + </row> + <row> + <entry> + Non-atomic + </entry> + <entry> + Update + </entry> + <entry> + Revision missing or incorrect + </entry> + <entry> + Resubmit with correct revision + </entry> + </row> + <row> + <entry> + All-or-nothing + </entry> + <entry> + Insert + </entry> + <entry> + Additional revision inserted + </entry> + <entry> + Resolve conflicted revisions + </entry> + </row> + <row> + <entry> + All-or-nothing + </entry> + <entry> + Update + </entry> + <entry> + Additional revision inserted + </entry> + <entry> + Resolve conflicted revisions + </entry> + </row> + </tbody> + </tgroup> + </table> + + <para> + Replication of documents is independent of the type of insert or + update. The documents and revisions created during a bulk insert + or update are replicated in the same way as any other document. + This can mean that if you make use of the all-or-nothing mode + the exact list of documents, revisions (and their conflict + state) may or may not be replicated to other databases + correctly. + </para> + + </section> + + <section id="couchdb-api-db_db-bulk-docs_post-errors"> + + <title>Bulk Document Validation and Conflict Errors</title> + + <para> + The JSON returned by the <literal>_bulk_docs</literal> operation + consists of an array of JSON structures, one for each document + in the original submission. The returned JSON structure should + be examined to ensure that all of the documents submitted in the + original request were successfully added to the database. + </para> + + <para> + The exact structure of the returned information is shown in + <xref + linkend="table-couchdb-api-db_db-bulk-docs-return-json"/>. + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-db_db-bulk-docs-return-json" class="jsonstructure"><title> + Bulk Document Response + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>docs</literal> <literal>[array]</literal> </entry><entry> + Bulk Docs Returned Documents + </entry></row><row><entry > <literal>error</literal> </entry><entry> + Error type + </entry></row><row><entry > <literal>id</literal> </entry><entry> + Document ID + </entry></row><row><entry > <literal>reason</literal> </entry><entry> + Error string with extended reason + </entry></row></tbody></tgroup></table> + + <para> + When a document (or document revision) is not correctly comitted + to the database because of an error, you should check the + <literal>error</literal> field to determine error type and + course of action. Errors will be one of the following type: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal>conflict</literal> + </para> + + <para> + The document as submitted is in conflict. If you used the + default bulk transaction mode then the new revision will not + have been created and you will need to re-submit the + document to the database. If you used + <literal>all-or-nothing</literal> mode then you will need to + manually resolve the conflicted revisions of the document. + </para> + + <para> + Conflict resolution of documents added using the bulk docs + interface is identical to the resolution procedures used + when resolving conflict errors during replication. + </para> + + + </listitem> + + <listitem> + <para> + <literal>forbidden</literal> + </para> + + <para> + Entries with this error type indicate that the validation + routine applied to the document during submission has + returned an error. + </para> + + <para> + For example, if your validation routine includes the + following: + </para> + +<programlisting> throw({forbidden: 'invalid recipe ingredient'});</programlisting> + + <para> + The error returned will be: + </para> + +<programlisting> +{ + "id" : "7f7638c86173eb440b8890839ff35433", + "error" : "forbidden", + "reason" : "invalid recipe ingredient" +} + </programlisting> + + <para> + For more information, see + <xref linkend="couchdb-api-functional-validation"/>. + </para> + </listitem> + + </itemizedlist> + + </section> + + </section> + + <section id="couchdb-api-db_db-temp-view_post"> + + <title><literal>POST /db/_temp_view</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_temp_view</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>POST /db/_temp_view</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON with the temporary view definition + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Temporary view result set + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">yes</entry></row></tbody></tgroup></informaltable> + + <para> + Creates (and executes) a temporary view based on the view function + supplied in the JSON request. For example: + </para> + +<programlisting> +POST http://couchdb:5984/recipes/_temp_view +Content-Type: application/json + +{ + "map" : "function(doc) { if (doc.value > 9995) { emit(null, doc.value); } }" +} +</programlisting> + + <para> + The resulting JSON response is the result from the execution of + the temporary view: + </para> + +<programlisting> +{ + "total_rows" : 3, + "rows" : [ + { + "value" : 9998.41913029012, + "id" : "05361cc6aa42033878acc1bacb1f39c2", + "key" : null + }, + { + "value" : 9998.94149934853, + "id" : "1f443f471e5929dd7b252417625ed170", + "key" : null + }, + { + "value" : 9998.01511339154, + "id" : "1f443f471e5929dd7b252417629c102b", + "key" : null + } + ], + "offset" : 0 +} +</programlisting> + + <para> + The arguments also available to standard view requests also apply + to temporary views, but the execution of the view may take some + time as it relies on being executed at the time of the request. In + addition to the time taken, they are also computationally very + expensive to produce. You should use a defined view if you want to + achieve the best performance. + </para> + + <para> + For more information, see + <xref linkend="couchdb-api-functional-views"/>. + </para> + + </section> + + <section id="couchdb-api-db_db-purge_post"> + + <title><literal>POST /db/_purge</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_purge</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>POST /db/_purge</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the document IDs/revisions to be purged + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON structure with purged documents and purge sequence + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + A database purge permanently removes the references to deleted + documents from the database. Deleting a document within CouchDB + does not actually remove the documen from the database, instead, + the document is marked as a deleted (and a new revision is + created). This is to ensure that deleted documents are replicated + to other databases as having been deleted. This also means that + you can check the status of a document and identify that the + document has been deleted. + </para> + + <para> + The purge operation removes the refernces to the deleted documents + from the database. The purging of old documents is not replicated + to other databases. If you are replicating between databases and + have deleted a large number of documents you should run purge on + each database. + </para> + + <note> + <para> + Purging documents does not remove the space used by them on + disk. To reclaim disk space, you should run a database compact + (see <xref + linkend="couchdb-api-db_db-compact_post"/>, and + compact views (see + <xref + linkend="couchdb-api-db_db-compact-design-doc_post"/>). + </para> + </note> + + <para> + To perform a purge operation you must send a request including the + JSON of the document IDs that you want to purge. For example: + </para> + +<programlisting> +POST http://couchdb:5984/recipes/_purge +Content-Type: application/json + +{ + "FishStew" : [ + "17-b3eb5ac6fbaef4428d712e66483dcb79" + ] +} +</programlisting> + + <para> + The format of the request must include the document ID and one or + more revisions that must be purged. + </para> + + <para> + The response will contain the purge sequence number, and a list of + the document IDs and revisions successfully purged. + </para> + +<programlisting> +{ + "purged" : { + "FishStew" : [ + "17-b3eb5ac6fbaef4428d712e66483dcb79" + ] + }, + "purge_seq" : 11 +} +</programlisting> + + <section id="couchdb-api-db_db-purge_post-indexrebuild"> + + <title>Updating Indexes</title> + + <para> + The number of purges on a database is tracked using a purge + sequence. This is used by the view indexer to optimize the + updating of views that contain the purged documents. + </para> + + <para> + When the indexer identifies that the purge sequence on a + database has changed, it compares the purge sequence of the + database with that stored in the view index. If the difference + between the stored sequence and database is sequence is only 1, + then the indexer uses a cached list of the most recently purged + documents, and then removes these documents from the index + individually. This prevents completely rebuilding the index from + scratch. + </para> + + <para> + If the difference between the stored sequence number and current + database sequence is greater than 1, then the view index is + entirely rebuilt. This is an expensive operation as every + document in the database must be examined. + </para> + + </section> + + </section> + + <section id="couchdb-api-db_db-all-docs_get"> + + <title><literal>GET /db/_all_docs</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_all_docs</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /db/_all_docs</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON object containing document information, ordered by the + document ID + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>descending</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return the documents in descending by key order + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>endkey</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Stop returning records when the specified key is reached + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>endkey_docid</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Stop returning records when the specified document ID is + reached + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>group</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Group the results using the reduce function to a group or + single row + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>group_level</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specify the group level to be used + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>include_docs</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Include the full content of the documents in the return + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>inclusive_end</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specifies whether the specified end key should be included + in the result + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>true</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>key</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return only documents that match the specified key + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>limit</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Limit the number of the returned documents to the specified + number + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>reduce</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Use the reduction function + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>true</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>skip</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Skip this number of records before starting to return the + results + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>0</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>stale</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Allow the results from a stale view to be used + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry></entry><entry><literal>ok</literal></entry><entry>Allow stale views</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>startkey</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return records starting with the specified key + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>startkey_docid</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return records starting with the specified document ID + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>update_seq</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Include the update sequence in the generated results + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row></tbody></tgroup></informaltable> + + <para> + Returns a JSON structure of all of the documents in a given + database. The information is returned as a JSON structure + containing meta information about the return structure, and the + list documents and basic contents, consisting the ID, revision and + key. The key is generated from the document ID. + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-db_db-all-docs" class="jsonstructure"><title> + All Database Documents + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>offset</literal> </entry><entry> + Offset where the document list started + </entry></row><row><entry ><literal>rows</literal> <literal>[array]</literal> </entry><entry> + Array of document object + </entry></row><row><entry ><literal>total_rows</literal> </entry><entry> + Number of documents in the database/view + </entry></row><row><entry ><literal>update_seq</literal> (optional) </entry><entry> + Current update sequence for the database + </entry></row></tbody></tgroup></table> + + <para> + By default the information returned contains only the document ID + and revision. For example, the request: + </para> + +<programlisting role="httprequest"> +GET http://couchdb:5984/recipes/_all_docs +Accept: application/json +</programlisting> + + <para> + Returns the following structure: + </para> + +<programlisting role="httpresponse"> +{ + "total_rows" : 18386, + "rows" : [ + { + "value" : { + "rev" : "1-bc0d5aed1e339b1cc1f29578f3220a45" + }, + "id" : "Aberffrawcake", + "key" : "Aberffrawcake" + }, + { + "value" : { + "rev" : "3-68a20c89a5e70357c20148f8e82ca331" + }, + "id" : "Adukiandorangecasserole-microwave", + "key" : "Adukiandorangecasserole-microwave" + }, + { + "value" : { + "rev" : "3-9b2851ed9b6f655cc4eb087808406c60" + }, + "id" : "Aioli-garlicmayonnaise", + "key" : "Aioli-garlicmayonnaise" + }, + ... + ], + "offset" : 0 +} +</programlisting> + + <para> + The information is returned in the form of a temporary view of all + the database documents, with the returned key consisting of the ID + of the document. The remainder of the interface is therefore + identical to the View query arguments and their behavior. + </para> + + + + </section> + + <section id="couchdb-api-db_db-all-docs_post"> + + <title><literal>POST /db/_all_docs</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_all_docs</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>POST /db/_all_docs</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the document IDs you want included + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the returned view + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + The <literal>POST</literal> to <literal>_all_docs</literal> allows + to specify multiple keys to be selected from the database. This + enables you to request multiple documents in a single request, in + place of multiple + <xref + linkend="couchdb-api-dbdoc_db-doc_get"/> requests. + </para> + + <para> + The request body should contain a list of the keys to be returned + as an array to a <literal>keys</literal> object. For example: + </para> + +<programlisting role="httprequest"> +POST http://couchdb:5984/recipes/_all_docs +User-Agent: MyApp/0.1 libwww-perl/5.837 + +{ + "keys" : [ + "Zingylemontart", + "Yogurtraita" + ] +} +</programlisting> + + <para> + The return JSON is the all documents structure, but with only the + selected keys in the output: + </para> + +<programlisting role="httpresponse"> +{ + "total_rows" : 2666, + "rows" : [ + { + "value" : { + "rev" : "1-a3544d296de19e6f5b932ea77d886942" + }, + "id" : "Zingylemontart", + "key" : "Zingylemontart" + }, + { + "value" : { + "rev" : "1-91635098bfe7d40197a1b98d7ee085fc" + }, + "id" : "Yogurtraita", + "key" : "Yogurtraita" + } + ], + "offset" : 0 +} +</programlisting> + + + + </section> + + <section id="couchdb-api-db_db-missing-revs_post"> + + <title><literal>POST /db/_missing_revs</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_missing_revs</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>POST /db/_missing_revs</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON list of document revisions + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of missing revisions + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + </section> + + <section id="couchdb-api-db_db-revs-diff_post"> + + <title><literal>POST /db/_revs_diff</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_revs_diff</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>POST /db/_revs_diff</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON list of document and revisions + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON list of differences from supplied document/revision list + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + </section> + + <section id="couchdb-api-db_db-security_get"> + + <title><literal>GET /db/_security</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_security</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /db/_security</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the security object + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Gets the current secrity object from the specified database. The + security object consists of two compulsory elements, + <literal>admins</literal> and <literal>readers</literal>, which + are used to specify the list of users and/or roles that have admin + and reader rights to the database respectively. Any additional + fields in the security object are optional. The entire security + object is made available to validation and other internal + functions so that the database can control and limit + functionality. + </para> + + <para> + To get the existing security object you would send the following + request: + </para> + +<programlisting> +{ + "admins" : { + "roles" : [], + "names" : [ + "mc", + "slp" + ] + }, + "readers" : { + "roles" : [], + "names" : [ + "tim", + "brian" + ] + } +} +</programlisting> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-db-json-security" class="jsonstructure"><title> + Security Object + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>admins</literal> </entry><entry> + Roles/Users with admin privileges + </entry></row><row><entry > <literal>roles</literal> <literal>[array]</literal> </entry><entry> + List of roles with parent privilege + </entry></row><row><entry > <literal>users</literal> <literal>[array]</literal> </entry><entry> + List of users with parent privilege + </entry></row><row><entry ><literal>readers</literal> </entry><entry> + Roles/Users with reader privileges + </entry></row><row><entry > <literal>roles</literal> <literal>[array]</literal> </entry><entry> + List of roles with parent privilege + </entry></row><row><entry > <literal>users</literal> <literal>[array]</literal> </entry><entry> + List of users with parent privilege + </entry></row></tbody></tgroup></table> + + <note> + <para> + If the security object for a database has never beent set, then + the value returned will be empty. + </para> + </note> + + </section> + + <section id="couchdb-api-db_db-security_put"> + + <title><literal>PUT /db/_security</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API PUT /db/_security</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>PUT /db/_security</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON specifying the admin and user security for the database + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON status message + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Sets the security object for the given database.For example, to + set the security object for the <literal>recipes</literal> + database: + </para> + +<programlisting> +PUT http://couchdb:5984/recipes/_security +Content-Type: application/json + +{ + "admins" : { + "roles" : [], + "names" : [ + "mc", + "slp" + ] + }, + "readers" : { + "roles" : [], + "names" : [ + "tim", + "brian" + ] + } +}</programlisting> + + <para> + If the setting was successful, a JSON status object will be + returned: + </para> + +<programlisting> +{ + "ok" : true +} +</programlisting> + + </section> + + <section id="couchdb-api-db_db-revs-limit_get"> + + <title><literal>GET /db/_revs_limit</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_revs_limit</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /db/_revs_limit</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + The current revision limit setting + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Gets the current <literal>revs_limit</literal> (revision limit) + setting. + </para> + + <para> + For example to get the current limit: + </para> + +<programlisting> +GET http://couchdb:5984/recipes/_revs_limit +Content-Type: application/json +</programlisting> + + <para> + The returned information is the current setting as a numerical + scalar: + </para> + +<programlisting> +1000 +</programlisting> + + </section> + + <section id="couchdb-api-db_db-revs-limit_put"> + + <title><literal>PUT /db/_revs_limit</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API PUT /db/_revs_limit</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>PUT /db/_revs_limit</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + A scalar integer of the revision limit setting + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Confirmation of setting of the revision limit + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Sets the maximum number of document revisions that will be tracked + by CouchDB, even after compaction has occurred. You can set the + revision limit on a database by using <literal>PUT</literal> with + a scalar integer of the limit that you want to set as the request + body. + </para> + + <para> + For example to set the revs limit to 100 for the + <literal>recipes</literal> database: + </para> + +<programlisting> +PUT http://couchdb:5984/recipes/_revs_limit +Content-Type: application/json + +100 +</programlisting> + + <para> + If the setting was successful, a JSON status object will be + returned: + </para> + +<programlisting> +{ + "ok" : true +} +</programlisting> + + </section> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-dbdoc.xml b/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-dbdoc.xml new file mode 100644 index 000000000..a924c2d71 --- /dev/null +++ b/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-dbdoc.xml @@ -0,0 +1,1091 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-api-dbdoc"> + + <title>CouchDB API Server Document Methods</title> + + <para> + The CouchDB API Server Document methods detail how to create, read, + update and delete documents within a database. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-dbdoc-summary"><title>Document API Calls</title><tgroup cols="3"><colspec colname="method"/><colspec colname="path"/><colspec colname="desc"/><thead><row><entry>Method</entry><entry>Path</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>POST</literal></entry><entry><literal>/db</literal></entry><entry><link linkend="couchdb-api-dbdoc_db_post"> + Create a new document + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/db/doc</literal></entry><entry><link linkend="couchdb-api-dbdoc_db-doc_get"> + Returns the latest revision of the document + </link></entry></row><row><entry><literal>HEAD</literal></entry><entry><literal>/db/doc</literal></entry><entry><link linkend="couchdb-api-dbdoc_db-doc_head"> + Returns bare information in the HTTP Headers for the document + </link></entry></row><row><entry><literal>PUT</literal></entry><entry><literal>/db/doc</literal></entry><entry><link linkend="couchdb-api-dbdoc_db-doc_put"> + Inserts a new document, or new version of an existing document + </link></entry></row><row><entry><literal>DELETE</literal></entry><entry><literal>/db/doc</literal></entry><entry><link linkend="couchdb-api-dbdoc_db-doc_delete"> + Deletes the document + </link></entry></row><row><entry><literal>COPY</literal></entry><entry><literal>/db/doc</literal></entry><entry><link linkend="couchdb-api-dbdoc_db-doc_copy"> + Copies the document + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/db/doc/attachment</literal></entry><entry><link linkend="couchdb-api-dbdoc_db-doc-attachment_get"> + Gets the attachment of a document + </link></entry></row><row><entry><literal>PUT</literal></entry><entry><literal>/db/doc/attachment</literal></entry><entry><link linkend="couchdb-api-dbdoc_db-doc-attachment_put"> + Adds an attachment of a document + </link></entry></row><row><entry><literal>DELETE</literal></entry><entry><literal>/db/doc/attachment</literal></entry><entry><link linkend="couchdb-api-dbdoc_db-doc-attachment_delete"> + Deletes an attachment of a document + </link></entry></row></tbody></tgroup></table> + + <section id="couchdb-api-dbdoc_db_post"> + + <title><literal>POST /db</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /db</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>POST /db</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the new document + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON with the committed document information + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>batch</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Allow document store request to be batched with others + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry></entry><entry><literal>ok</literal></entry><entry>Enable</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>201</entry><entry namest="info" nameend="addinfo"> + Document has been created successfully + </entry></row><row><entry>409</entry><entry namest="info" nameend="addinfo"> + Conflict - a document with the specified document ID already + exists + </entry></row></tbody></tgroup></informaltable> + + <para> + Create a new document in the specified database, using the + supplied JSON document structure. If the JSON structure includes + the <literal>_id</literal> field, then the document will be + created with the specified document ID. If the + <literal>_id</literal> field is not specified, a new unique ID + will be generated. + </para> + + <para> + For example, you can generate a new document with a generated UUID + using the following request: + </para> + +<programlisting> +POST http://couchdb:5984/recipes/ +Content-Type: application/json + +{ + "servings" : 4, + "subtitle" : "Delicious with fresh bread", + "title" : "Fish Stew" +} +</programlisting> + + <para> + The return JSON will specify the automatically enerated ID and + revision information: + </para> + +<programlisting> +{ + "id" : "64575eef70ab90a2b8d55fc09e00440d", + "ok" : true, + "rev" : "1-9c65296036141e575d32ba9c034dd3ee" +} +</programlisting> + + <section id="couchdb-api-dbdoc_db_post-docid"> + + <title>Specifying the Document ID</title> + + <para> + The document ID can be specified by including the + <literal>_id</literal> field in the JSON of the submitted + record. The following request will create the same document with + the ID <literal>FishStew</literal>: + </para> + +<programlisting> +POST http://couchdb:5984/recipes/ +Content-Type: application/json + +{ + "_id" : "FishStew", + "servings" : 4, + "subtitle" : "Delicious with fresh bread", + "title" : "Fish Stew" +} +</programlisting> + + <para> + The structure of the submitted document is as shown in the table + below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-json-document" class="jsonstructure"><title> + CouchDB Document + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry ><literal>_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row></tbody></tgroup></table> + + <para> + In either case, the returned JSON will specify the document ID, + revision ID, and status message: + </para> + +<programlisting> +{ + "id" : "FishStew", + "ok" : true, + "rev" : "1-9c65296036141e575d32ba9c034dd3ee" +} + </programlisting> + + </section> + + <section id="couchdb-api-dbdoc_db_batchmode"> + + <title>Batch Mode Writes</title> + + <para> + You can write documents to the database at a higher rate by + using the batch option. This collects document writes together + in memory (on a user-by-user basis) before they are committed to + disk. This increases the risk of the documents not being stored + in the event of a failure, since the documents are not written + to disk immediately. + </para> + + <para> + To use the batched mode, append the <literal>batch=ok</literal> + query argument to the URL of the <literal>PUT</literal> or + <literal>POST</literal> request. The CouchDB server will respond + with a 202 HTTP response code immediately. + </para> + + </section> + + <section id="couchdb-api-dbdoc_db-doc-attachments"> + + <title>Including Attachments</title> + + <para> + You can include one or more attachments with a given document by + incorporating the attachment information within the JSON of the + document. This provides a simpler alternative to loading + documents with attachments than making a separate call (see + <xref + linkend="couchdb-api-dbdoc_db-doc-attachment_put"/>). + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-dbdoc-documentattachments" class="jsonstructure"><title> + Document with Attachments + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry ><literal>_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row><row><entry ><literal>_attachments</literal> (optional) </entry><entry> + Document Attachment + </entry></row><row><entry > <literal>filename</literal> </entry><entry> + Attachment information + </entry></row><row><entry > <literal>content_type</literal> </entry><entry> + MIME Content type string + </entry></row><row><entry > <literal>data</literal> </entry><entry> + File attachment content, Base64 encoded + </entry></row></tbody></tgroup></table> + + <para> + The <literal>filename</literal> will be the attachment name. For + example, when sending the JSON structure below: + </para> + +<programlisting> +{ + "_id" : "FishStew", + "servings" : 4, + "subtitle" : "Delicious with fresh bread", + "title" : "Fish Stew" + "_attachments" : { + "styling.css" : { + "content-type" : "text/css", + "data" : "cCB7IGZvbnQtc2l6ZTogMTJwdDsgfQo=", + }, + }, +} + </programlisting> + + <para> + The attachment <literal>styling.css</literal> can be accessed + using <literal>/recipes/FishStew/styling.css</literal>. For more + information on attachments, see + <xref + linkend="couchdb-api-dbdoc_db-doc-attachment_get"/>. + </para> + + <para> + The document data embedded in to the structure must be encoded + using base64. + </para> + + </section> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_get"> + + <title><literal>GET /db/doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /db/doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /db/doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Returns the JSON for the document + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>conflicts</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Returns the conflict tree for the document. + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry></entry><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry></entry><entry><literal>true</literal></entry><entry>Includes the revisions</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>rev</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specify the revision to return + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry></entry><entry><literal>true</literal></entry><entry>Includes the revisions</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>revs</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return a list of the revisions for the document + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>revs_info</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return a list of detailed revision information for the + document + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry></entry><entry><literal>true</literal></entry><entry>Includes the revisions</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>201</entry><entry namest="info" nameend="addinfo"> + Document created + </entry></row><row><entry>400</entry><entry namest="info" nameend="addinfo"> + The format of the request or revision was invalid + </entry></row><row><entry>404</entry><entry namest="info" nameend="addinfo"> + The specified document or revision cannot be found, or has been + deleted + </entry></row><row><entry>409</entry><entry namest="info" nameend="addinfo"> + Conflict - a document with the specified document ID already + exists + </entry></row></tbody></tgroup></informaltable> + + <para> + Returns the specified <literal>doc</literal> from the specified + <literal>db</literal>. For example, to retrieve the document with + the id <literal>FishStew</literal> you would send the following + request: + </para> + +<programlisting> +GET http://couchdb:5984/recipes/FishStew +Content-Type: application/json +Accept: application/json +</programlisting> + + <para> + The returned JSON is the JSON of the document, including the + document ID and revision number: + </para> + +<programlisting> +{ + "_id" : "FishStew", + "_rev" : "3-a1a9b39ee3cc39181b796a69cb48521c", + "servings" : 4, + "subtitle" : "Delicious with a green salad", + "title" : "Irish Fish Stew" +} + </programlisting> + + <para> + Unless you request a specific revision, the latest revision of the + document will always be returned. + </para> + + <section id="couchdb-api-dbdoc_db-doc_get-attachments"> + + <title>Attachments</title> + + <para> + If the document includes attachments, then the returned + structure will contain a summary of the attachments associatd + with the document, but not the attachment data itself. + </para> + + <para> + The JSON for the returned document will include the + <literal>_attachments</literal> field, with one or more + attachment definitions. For example: + </para> + +<programlisting> +{ + "_id" : "FishStew", + "servings" : 4, + "subtitle" : "Delicious with fresh bread", + "title" : "Fish Stew" + "_attachments" : { + "styling.css" : { + "stub" : true, + "content-type" : "text/css", + "length" : 783426, + }, + }, +} +</programlisting> + + <para> + The format of the returned JSON is shown in the table below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-dbdoc-returneddocumentattachments" class="jsonstructure"><title> + Returned Document with Attachments + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry ><literal>_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row><row><entry ><literal>_attachments</literal> (optional) </entry><entry> + Document Attachment + </entry></row><row><entry > <literal>filename</literal> </entry><entry> + Attachment + </entry></row><row><entry > <literal>content_type</literal> </entry><entry> + MIME Content type string + </entry></row><row><entry > <literal>length</literal> </entry><entry> + Length (bytes) of the attachment data + </entry></row><row><entry > <literal>revpos</literal> </entry><entry> + Revision where this attachment exists + </entry></row><row><entry > <literal>stub</literal> </entry><entry> + Indicates whether the attachment is a stub + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_get-revs"> + + <title>Getting a List of Revisions</title> + + <para> + You can obtain a list of the revisions for a given document by + adding the <literal>revs=true</literal> parameter to the request + URL. For example: + </para> + +<programlisting> +GET http://couchdb:5984/recipes/FishStew?revs=true +Accept: application/json +</programlisting> + + <para> + The returned JSON structure includes the original document, + including a <literal>_revisions</literal> structure that + includes the revision information: + </para> + +<programlisting> +{ + "servings" : 4, + "subtitle" : "Delicious with a green salad", + "_id" : "FishStew", + "title" : "Irish Fish Stew", + "_revisions" : { + "ids" : [ + "a1a9b39ee3cc39181b796a69cb48521c", + "7c4740b4dcf26683e941d6641c00c39d", + "9c65296036141e575d32ba9c034dd3ee" + ], + "start" : 3 + }, + "_rev" : "3-a1a9b39ee3cc39181b796a69cb48521c" +} +</programlisting> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-dbdoc-document_with_revs" class="jsonstructure"><title> + Returned CouchDB Document with Revision Info + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry ><literal>_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row><row><entry ><literal>_revisions</literal> </entry><entry> + CouchDB Document Revisions + </entry></row><row><entry > <literal>ids</literal> <literal>[array]</literal> </entry><entry> + Array of valid revision IDs, in reverse order (latest first) + </entry></row><row><entry > <literal>start</literal> </entry><entry> + Prefix number for the latest revision + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_get-revsextended"> + + <title>Obtaining an Extended Revision History</title> + + <para> + You can get additional information about the revisions for a + given document by supplying the <literal>revs_info</literal> + argument to the query: + </para> + +<programlisting> +GET http://couchdb:5984/recipes/FishStew?revs_info=true +Accept: application/json +</programlisting> + + <para> + This returns extended revision information, including the + availability and status of each revision: + </para> + +<programlisting> +{ + "servings" : 4, + "subtitle" : "Delicious with a green salad", + "_id" : "FishStew", + "_revs_info" : [ + { + "status" : "available", + "rev" : "3-a1a9b39ee3cc39181b796a69cb48521c" + }, + { + "status" : "available", + "rev" : "2-7c4740b4dcf26683e941d6641c00c39d" + }, + { + "status" : "available", + "rev" : "1-9c65296036141e575d32ba9c034dd3ee" + } + ], + "title" : "Irish Fish Stew", + "_rev" : "3-a1a9b39ee3cc39181b796a69cb48521c" +} +</programlisting> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-dbdoc-document_with_revs_info" class="jsonstructure"><title> + Returned CouchDB Document with Detailed Revision Info + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry ><literal>_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row><row><entry ><literal>_revs_info</literal> <literal>[array]</literal> </entry><entry> + CouchDB Document Extended Revision Info + </entry></row><row><entry > <literal>rev</literal> </entry><entry> + Full revision string + </entry></row><row><entry > <literal>status</literal> </entry><entry> + Status of the revision + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_get-specrev"> + + <title>Obtaining a Specific Revision</title> + + <para> + To get a specific revision, use the <literal>rev</literal> + argument to the request, and specify the full revision number: + </para> + +<programlisting> +GET http://couchdb:5984/recipes/FishStew?rev=2-7c4740b4dcf26683e941d6641c00c39d +Accept: application/json +</programlisting> + + <para> + The specified revision of the document will be returned, + including a <literal>_rev</literal> field specifying the + revision that was requested: + </para> + +<programlisting> +{ + "_id" : "FishStew", + "_rev" : "2-7c4740b4dcf26683e941d6641c00c39d", + "servings" : 4, + "subtitle" : "Delicious with a green salad", + "title" : "Fish Stew" +} +</programlisting> + + </section> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_head"> + + <title><literal>HEAD /db/doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API HEAD /db/doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>HEAD /db/doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>rev</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specify the revision to return + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>revs</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return a list of the revisions for the document + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>revs_info</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return a list of detailed revision information for the + document + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>404</entry><entry namest="info" nameend="addinfo"> + The specified document or revision cannot be found, or has been + deleted + </entry></row></tbody></tgroup></informaltable> + + <para> + Returns the HTTP Headers containing a minimal amount of + information about the specified document. The method supports the + same query arguments as the <literal>GET</literal> method, but + only the header information (including document size, and the + revision as an ETag), is returned. For example, a simple + <literal>HEAD</literal> request: + </para> + +<programlisting> +HEAD http://couchdb:5984/recipes/FishStew +Content-Type: application/json + </programlisting> + + <para> + Returns the following HTTP Headers: + </para> + +<programlisting> +HTTP/1.1 200 OK +Server: CouchDB/1.0.1 (Erlang OTP/R13B) +Etag: "7-a19a1a5ecd946dad70e85233ba039ab2" +Date: Fri, 05 Nov 2010 14:54:43 GMT +Content-Type: text/plain;charset=utf-8 +Content-Length: 136 +Cache-Control: must-revalidate +</programlisting> + + <para> + The <literal>Etag</literal> header shows the current revision for + the requested document, and the <literal>Content-Length</literal> + specifies the length of the data, if the document were requested + in full. + </para> + + <para> + Adding any of the query arguments (as supported by + <link linkend="couchdb-api-dbdoc_db-doc_get"><literal>GET</literal></link> + method), then the resulting HTTP Headers will correspond to what + would be returned. Note that the current revision is not returned + when the <literal>refs_info</literal> argument is used. For + example: + </para> + +<programlisting> +HTTP/1.1 200 OK +Server: CouchDB/1.0.1 (Erlang OTP/R13B) +Date: Fri, 05 Nov 2010 14:57:16 GMT +Content-Type: text/plain;charset=utf-8 +Content-Length: 609 +Cache-Control: must-revalidate +</programlisting> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_put"> + + <title><literal>PUT /db/doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API PUT /db/doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>PUT /db/doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the new document, or updated version of the existed + document + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the document ID and revision + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>batch</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Allow document store request to be batched with others + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry></entry><entry><literal>ok</literal></entry><entry>Enable</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal>If-Match</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry>Current revision of the document for validation</entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>201</entry><entry namest="info" nameend="addinfo"> + Document has been created successfully + </entry></row><row><entry>202</entry><entry namest="info" nameend="addinfo"> + Document accepted for writing (batch mode) + </entry></row></tbody></tgroup></informaltable> + + <para> + The <literal>PUT</literal> method creates a new named document, or + creates a new revision of the existing document. Unlike the + <link linkend="couchdb-api-dbdoc_db_post"><literal>POST</literal></link> + method, you must specify the document ID in the request URL. + </para> + + <para> + For example, to create the docment <literal>FishStew</literal>, + you would send the following request: + </para> + +<programlisting>PUT http://couchdb:5984/recipes/FishStew +Content-Type: application/json + +{ + "servings" : 4, + "subtitle" : "Delicious with fresh bread", + "title" : "Fish Stew" +} +</programlisting> + + <para> + The return type is JSON of the status, document ID,and revision + number: + </para> + +<programlisting> +{ + "id" : "FishStew", + "ok" : true, + "rev" : "1-9c65296036141e575d32ba9c034dd3ee" +} +</programlisting> + + <section id="couchdb-api-dbdoc_db-doc_put-update"> + + <title>Updating an Existing Document</title> + + <para> + To update an existing document you must specify the current + revision number within the <literal>_rev</literal> parameter. + For example: + </para> + +<programlisting> +PUT http://couchdb:5984/recipes/FishStew +Content-Type: application/json + +{ + "_rev" : "1-9c65296036141e575d32ba9c034dd3ee", + "servings" : 4, + "subtitle" : "Delicious with fresh salad", + "title" : "Fish Stew" +} +</programlisting> + + <para> + Alternatively, you can supply the current revision number in the + <literal>If-Match</literal> HTTP header of the request. For + example: + </para> + +<programlisting> +PUT http://couchdb:5984/recipes/FishStew +If-Match: 2-d953b18035b76f2a5b1d1d93f25d3aea +Content-Type: application/json + +{ + "servings" : 4, + "subtitle" : "Delicious with fresh salad", + "title" : "Fish Stew" +} +</programlisting> + + <para> + The JSON returned will include the updated revision number: + </para> + +<programlisting> +{ + "id" : "FishStew99", + "ok" : true, + "rev" : "2-d953b18035b76f2a5b1d1d93f25d3aea" +} +</programlisting> + + <para> + For information on batched writes, which can provide improved + performance, see + <xref linkend="couchdb-api-dbdoc_db_batchmode"/>. + </para> + + </section> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_delete"> + + <title><literal>DELETE /db/doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API DELETE /db/doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>DELETE /db/doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the deleted revision + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>rev</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Current revision of the document for validation + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal>If-Match</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry>Current revision of the document for validation</entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>409</entry><entry namest="info" nameend="addinfo"> + Revision is missing, invalid or not the latest + </entry></row></tbody></tgroup></informaltable> + + <para> + Deletes the specified document from the database. You must supply + the current (latest) revision, either by using the + <literal>rev</literal> parameter to specify the revision: + </para> + +<programlisting> +DELETE http://couchdb:5984/recipes/FishStew?rev=3-a1a9b39ee3cc39181b796a69cb48521c +Content-Type: application/json +</programlisting> + + <para> + Alternatively, you can use ETags with the + <literal>If-Match</literal> field: + </para> + +<programlisting> +DELETE http://couchdb:5984/recipes/FishStew +If-Match: 3-a1a9b39ee3cc39181b796a69cb48521c +Content-Type: application/json + </programlisting> + + <para> + The returned JSON contains the document ID, revision and status: + </para> + +<programlisting> +{ + "id" : "FishStew", + "ok" : true, + "rev" : "4-2719fd41187c60762ff584761b714cfb" +} +</programlisting> + + <note> + <para> + Note that deletion of a record increments the revision number. + The use of a revision for deletion of the record allows + replication of the database to correctly track the deletion in + synchronized copies. + </para> + </note> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_copy"> + + <title><literal>COPY /db/doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API COPY /db/doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>COPY /db/doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the new document and revision + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>rev</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Revision to copy from + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal>Destination</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry>Destination document (and optional revision)</entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>no</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>201</entry><entry namest="info" nameend="addinfo"> + Document has been copied and created successfully + </entry></row><row><entry>409</entry><entry namest="info" nameend="addinfo"> + Conflict (target document already exists) + </entry></row></tbody></tgroup></informaltable> + + <para> + The <literal>COPY</literal> command (which is non-standard HTTP) + copies an existing document to a new or existing document. + </para> + + <para> + The source document is specified on the request line, with the + <literal>Destination</literal> HTTP Header of the request + specifying the target document. + </para> + + <section id="couchdb-api-dbdoc_db-doc_copy-simple"> + + <title>Copying a Document</title> + + <para> + You can copy the latest version of a document to a new document + by specifying the current document and target document: + </para> + +<programlisting> +COPY http://couchdb:5984/recipes/FishStew +Content-Type: application/json +Destination: IrishFishStew +</programlisting> + + <para> + The above request copies the document + <literal>FishStew</literal> to the new document + <literal>IrishFishStew</literal>. The response is the ID and + revision of the new document. + </para> + +<programlisting> +{ + "id" : "IrishFishStew", + "rev" : "1-9c65296036141e575d32ba9c034dd3ee" +} +</programlisting> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_copy-specrev"> + + <title>Copying from a Specific Revision</title> + + <para> + To copy <emphasis>from</emphasis> a specific version, use the + <literal>rev</literal> argument to the query string: + </para> + +<programlisting> +COPY http://couchdb:5984/recipes/FishStew?rev=5-acfd32d233f07cea4b4f37daaacc0082 +Content-Type: application/json +Destination: IrishFishStew +</programlisting> + + <para> + The new document will be created using the information in the + specified revision of the source document. + </para> + + </section> + + <section id="couchdb-api-dbdoc_db-doc_copy-existing"> + + <title>Copying to an Existing Document</title> + + <para> + To copy to an existing document, you must specify the current + revision string for the target document, using the + <literal>rev</literal> parameter to the + <literal>Destination</literal> HTTP Header string. For example: + </para> + +<programlisting> +COPY http://couchdb:5984/recipes/FishStew +Content-Type: application/json +Destination: IrishFishStew?rev=1-9c65296036141e575d32ba9c034dd3ee +</programlisting> + + <para> + The return value will be the new revision of the copied + document: + </para> + +<programlisting> +{ + "id" : "IrishFishStew", + "rev" : "2-55b6a1b251902a2c249b667dab1c6692" +} +</programlisting> + + </section> + + </section> + + <section id="couchdb-api-dbdoc_db-doc-attachment_get"> + + <title><literal>GET /db/doc/attachment</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /db/doc/attachment</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /db/doc/attachment</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Returns the document data + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Returns the file attachment <literal>attachment</literal> + associated with the document <literal>doc</literal>. The raw data + of the associated attachment is returned (just as if you were + accessing a static file. The returned HTTP + <literal>Content-type</literal> will be the same as the content + type set when the document attachment was submitted into the + database. + </para> + + </section> + + <section id="couchdb-api-dbdoc_db-doc-attachment_put"> + + <title><literal>PUT /db/doc/attachment</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API PUT /db/doc/attachment</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>PUT /db/doc/attachment</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + Raw document data + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON document status + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>rev</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Current document revision + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>no</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal>Content-Length</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry>Length (bytes) of the attachment being uploaded</entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>no</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal>Content-Type</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry>MIME type for the uploaded attachment</entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>no</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal>If-Match</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry>Current revision of the document for validation</entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>201</entry><entry namest="info" nameend="addinfo"> + Attachment has been accepted + </entry></row></tbody></tgroup></informaltable> + + <para> + Upload the supplied content as an attachment to the specified + document (<literal>doc</literal>). The + <literal>attachment</literal> name provided must be a URL encoded + string. You must also supply either the <literal>rev</literal> + query argument or the <literal>If-Match</literal> HTTP header for + validation, and the HTTP headers (to set the attacment content + type). The content type is used when the attachment is requested + as the corresponding content-type in the returned document header. + </para> + + <para> + For example, you could upload a simple text document using the + following request: + </para> + +<programlisting> +PUT http://couchdb:5984/recipes/FishStew/basic?rev=8-a94cb7e50ded1e06f943be5bfbddf8ca +Content-Length: 10 +Content-Type: text/plain + +Roast it + +</programlisting> + + <para> + Or by using the <literal>If-Match</literal> HTTP header: + </para> + +<programlisting> +PUT http://couchdb:5984/recipes/FishStew/basic +If-Match: 8-a94cb7e50ded1e06f943be5bfbddf8ca +Content-Length: 10 +Content-Type: text/plain + +Roast it + +</programlisting> + + <para> + The returned JSON contains the new document information: + </para> + +<programlisting> +{ + "id" : "FishStew", + "ok" : true, + "rev" : "9-247bb19a41bfd9bfdaf5ee6e2e05be74" +} +</programlisting> + + <note> + <para> + Uploading an attachment updates the corresponding document + revision. Revisions are tracked for the parent document, not + individual attachments. + </para> + </note> + + <section id="couchdb-api-dbdoc_db-doc-attachment_put-existing"> + + <title>Updating an Existing Attachment</title> + + <para> + Uploading an attachment using an existing attachment name will + update the corresponding stored content of the database. Since + you must supply the revision information to add an attachment to + a document, this serves as validation to update the existing + attachment. + </para> + + </section> + + </section> + + <section id="couchdb-api-dbdoc_db-doc-attachment_delete"> + + <title><literal>DELETE /db/doc/attachment</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API DELETE /db/doc/attachment</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>DELETE /db/doc/attachment</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON status + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>rev</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Revision of the document to be deleted + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>no</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal>If-Match</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry>Current revision of the document for validation</entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Attachment deleted successfully + </entry></row><row><entry>409</entry><entry namest="info" nameend="addinfo"> + Supplied revision is incorrect or missing + </entry></row></tbody></tgroup></informaltable> + + <para> + Deletes the attachment <literal>attachment</literal> to the + specified <literal>doc</literal>. You must supply the + <literal>rev</literal> argument with the current revision to + delete the attachment. + </para> + + <para> + For example to delete the attachment <literal>basic</literal> from + the recipe <literal>FishStew</literal>: + </para> + +<programlisting> +DELETE http://couchdb:5984/recipes/FishStew/basic?rev=9-247bb19a41bfd9bfdaf5ee6e2e05be74 +Content-Type: application/json + + </programlisting> + + <para> + The returned JSON contains the updated revision information: + </para> + +<programlisting> +{ + "id" : "FishStew", + "ok" : true, + "rev" : "10-561bf6b1e27615cee83d1f48fa65dd3e" +} +</programlisting> + + </section> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-design.xml b/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-design.xml new file mode 100644 index 000000000..acf08eb7c --- /dev/null +++ b/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-design.xml @@ -0,0 +1,1543 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-api-design"> + + <title>CouchDB API Server Design Document Methods</title> + + <para> + In CouchDB, design documents provide the main interface for building + a CouchDB application. The design document defines the views used to + extract information from CouchDB through one or more views. Design + documents are created within your CouchDB instance in the same way + as you create database documents, but the content and definition of + the documents is different. Design Documents are named using an ID + defined with the design document URL path, and this URL can then be + used to access the database contents. + </para> + + <para> + Views and lists operate together to provide automated (and + formatted) output from your database. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-design-summary"><title>Design Document API Calls</title><tgroup cols="3"><colspec colname="method"/><colspec colname="path"/><colspec colname="desc"/><thead><row><entry>Method</entry><entry>Path</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>GET</literal></entry><entry><literal>/db/_design/design-doc</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc_get"> + Returns the latest revision of the design document + </link></entry></row><row><entry><literal>PUT</literal></entry><entry><literal>/db/_design/design-doc</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc_put"> + Creates or updates a design document + </link></entry></row><row><entry><literal>DELETE</literal></entry><entry><literal>/db/_design/design-doc</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc_delete"> + Deletes the design document + </link></entry></row><row><entry><literal>COPY</literal></entry><entry><literal>/db/_design/design-doc</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc_copy"> + Copies the design document + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/db/_design/design-doc/_info</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-info_get"> + Returns information about the design document + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/db/_design/design-doc/_list/list-name/other-design-doc/view-name</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-list-listname-otherdesigndoc-viewname_get"> + Invokes the list handler to translate the given view results + </link></entry></row><row><entry><literal>POST</literal></entry><entry><literal>/db/_design/design-doc/_list/list-name/other-design-doc/view-name</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-list-listname-otherdesigndoc-viewname_post"> + Invokes the list handler to translate the given view results for + certain documents + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/db/_design/design-doc/_list/list-name/view-name</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-list-listname-viewname_get"> + Invokes the list handler to translate the given view results + </link></entry></row><row><entry><literal>POST</literal></entry><entry><literal>/db/_design/design-doc/_list/list-name/view-name</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-list-listname-viewname_post"> + Invokes the list handler to translate the given view results for + certain documents + </link></entry></row><row><entry><literal>ALL</literal></entry><entry><literal>/db/_design/design-doc/_rewrite/rewrite-name/anything</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-rewrite-rewritename-anything_all"> + Invokes the URL rewrite handler and processes the request after + rewriting + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/db/_design/design-doc/_show/show-name</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-show-showname_get"> + Invokes the show handler without a document + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/db/_design/design-doc/_show/show-name/doc</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-show-showname-doc_get"> + Invokes the show handler for the given document + </link></entry></row><row><entry><literal>POST</literal></entry><entry><literal>/db/_design/design-doc/_update/update-name</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-update-updatename_post"> + Invokes the update handler without a document ID + </link></entry></row><row><entry><literal>PUT</literal></entry><entry><literal>/db/_design/design-doc/_update/update-name/doc</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-update-updatename-doc_put"> + Invokes the update handler with a specific document ID + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/db/_design/design-doc/_view/view-name</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-view-viewname_get"> + Returns results of the view + </link></entry></row><row><entry><literal>POST</literal></entry><entry><literal>/db/_design/design-doc/_view/view-name</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-view-viewname_post"> + Returns certain rows from the view + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/db/_design/design-doc/attachment</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-attachment_get"> + Gets an attachment of the design document + </link></entry></row><row><entry><literal>PUT</literal></entry><entry><literal>/db/_design/design-doc/attachment</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-attachment_put"> + Inserts an attachment to the design document + </link></entry></row><row><entry><literal>DELETE</literal></entry><entry><literal>/db/_design/design-doc/attachment</literal></entry><entry><link linkend="couchdb-api-design_db-design-designdoc-attachment_delete"> + Deletes an attachment from the design document + </link></entry></row></tbody></tgroup></table> + + <section id="couchdb-api-design_db-design-designdoc_get"> + + <title><literal>GET /db/_design/design-doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_design/design-doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /db/_design/design-doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the existing design document + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>rev</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specify the revision to return + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>revs</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return a list of the revisions for the document + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry></entry><entry><literal>true</literal></entry><entry>Includes the revisions</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>revs_info</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return a list of detailed revision information for the + document + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry></entry><entry><literal>true</literal></entry><entry>Includes the revisions</entry></row></tbody></tgroup></informaltable> + + <para> + Returns the specified design document, + <literal>design-doc</literal> from the specified + <literal>db</literal>. For example, to retrieve the design + document <literal>recipes</literal> you would send the following + request: + </para> + +<programlisting> +GET http://couchdb:5984/recipes/_design/recipes +Content-Type: application/json +</programlisting> + + <para> + The returned string will be the JSON of the design document: + </para> + +<programlisting> +{ + "_id" : "_design/recipes", + "_rev" : "5-39f56a392b86bbee57e2138921346406" + "language" : "javascript", + "views" : { + "by_recipe" : { + "map" : "function(doc) { if (doc.title != null) emit(doc.title, doc) }" + }, + }, +} +</programlisting> + + <para> + A list of the revisions can be obtained by using the + <literal>revs</literal> query argument, or an extended list of + revisions using the <literal>revs_info</literal> query argument. + This operates in the same way as for other documents. Fur further + examples, see + <xref + linkend="couchdb-api-dbdoc_db-doc_get"/>. + </para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc_put"> + + <title><literal>PUT /db/_design/design-doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API PUT /db/_design/design-doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>PUT /db/_design/design-doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the design document + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON status + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Upload the specified design document, + <literal>design-doc</literal>, to the specified database. The + design document should follow the definition of a design document, + as summarised in the following table. + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-json-designdoc" class="jsonstructure"><title> + Design Document + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>_id</literal> </entry><entry> + Design Document ID + </entry></row><row><entry ><literal>_rev</literal> </entry><entry> + Design Document Revision + </entry></row><row><entry ><literal>views</literal> </entry><entry> + View + </entry></row><row><entry > <literal>viewname</literal> </entry><entry> + View Definition + </entry></row><row><entry > <literal>map</literal> </entry><entry> + Map Function for View + </entry></row><row><entry > <literal>reduce</literal> (optional) </entry><entry> + Reduce Function for View + </entry></row></tbody></tgroup></table> + + <para> + For more information on writing views, see + <xref + linkend="couchdb-api-functional-views"/>. + </para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc_delete"> + + <title><literal>DELETE /db/_design/design-doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API DELETE /db/_design/design-doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>DELETE /db/_design/design-doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of deleted design document + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>rev</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Current revision of the document for validation + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal>If-Match</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry>Current revision of the document for validation</entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>409</entry><entry namest="info" nameend="addinfo"> + Supplied revision is incorrect or missing + </entry></row></tbody></tgroup></informaltable> + + <para> + Delete an existing design document. Deleting a design document + also deletes all of the associated view indexes, and recovers the + corresponding space on disk for the indexes in question. + </para> + + <para> + To delete, you must specify the current revision of the design + document using the <literal>rev</literal> query argument. + </para> + + <para> + For example: + </para> + +<programlisting> +DELETE http://couchdb:5984/recipes/_design/recipes?rev=2-ac58d589b37d01c00f45a4418c5a15a8 +Content-Type: application/json +</programlisting> + + <para> + The response contains the delete document ID and revision: + </para> + +<programlisting> +{ + "id" : "recipe/_design/recipes" + "ok" : true, + "rev" : "3-7a05370bff53186cb5d403f861aca154", +} +</programlisting> + + </section> + + <section id="couchdb-api-design_db-design-designdoc_copy"> + + <title><literal>COPY /db/_design/design-doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API COPY /db/_design/design-doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>COPY /db/_design/design-doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the copied document and revision + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>rev</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Revision to copy from + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal>Destination</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry>Destination document (and optional revision)</entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>no</entry></row><row><entry></entry><entry></entry><entry></entry></row></tbody></tgroup></informaltable> + + <para> + The <literal>COPY</literal> command (non-standard HTTP) copies an + existing design document to a new or existing document. + </para> + + <para> + The source design document is specified on the request line, with + the <literal>Destination</literal> HTTP Header of the request + specifying the target document. + </para> + + <section id="couchdb-api-design_db-design-designdoc_copy-simple"> + + <title>Copying a Design Document</title> + + <para> + To copy the latest version of a design document to a new + document you specify the base document and target document: + </para> + +<programlisting> +COPY http://couchdb:5984/recipes/_design/recipes +Content-Type: application/json +Destination: /recipes/_design/recipelist +</programlisting> + + <para> + The above request copies the design document + <literal>recipes</literal> to the new design document + <literal>recipelist</literal>. The response is the ID and + revision of the new document. + </para> + +<programlisting> +{ + "id" : "recipes/_design/recipelist" + "rev" : "1-9c65296036141e575d32ba9c034dd3ee", +} +</programlisting> + + <note> + <para> + Copying a design document does automatically reconstruct the + view indexes. These will be recreated, as with other views, + the first time the new view is accessed. + </para> + </note> + + </section> + + <section id="couchdb-api-design_db-design-designdoc_copy-specrev"> + + <title>Copying from a Specific Revision</title> + + <para> + To copy <emphasis>from</emphasis> a specific version, use the + <literal>rev</literal> argument to the query string: + </para> + +<programlisting> +COPY http://couchdb:5984/recipes/_design/recipes?rev=1-e23b9e942c19e9fb10ff1fde2e50e0f5 +Content-Type: application/json +Destination: recipes/_design/recipelist +</programlisting> + + <para> + The new design document will be created using the specified + revision of the source document. + </para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc_copy-existing"> + + <title>Copying to an Existing Design Document</title> + + <para> + To copy to an existing document, you must specify the current + revision string for the target document, using the + <literal>rev</literal> parameter to the + <literal>Destination</literal> HTTP Header string. For example: + </para> + +<programlisting> +COPY http://couchdb:5984/recipes/_design/recipes +Content-Type: application/json +Destination: recipes/_design/recipelist?rev=1-9c65296036141e575d32ba9c034dd3ee +</programlisting> + + <para> + The return value will be the new revision of the copied + document: + </para> + +<programlisting> +{ + "id" : "recipes/_design/recipes" + "rev" : "2-55b6a1b251902a2c249b667dab1c6692", +} +</programlisting> + + </section> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-attachment_get"> + + <title><literal>GET /db/_design/design-doc/attachment</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_design/design-doc/attachment</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /db/_design/design-doc/attachment</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Document content + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Returns the file attachment <literal>attachment</literal> + associated with the design document + <literal>/_design_/design-doc</literal>. The raw data of the + associated attachment is returned (just as if you were accessing a + static file. The returned HTTP <literal>Content-type</literal> + will be the same as the content type set when the document + attachment was submitted into the database. + </para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-attachment_put"> + + <title><literal>PUT /db/_design/design-doc/attachment</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API PUT /db/_design/design-doc/attachment</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>PUT /db/_design/design-doc/attachment</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the design document + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON status statement + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>rev</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Current revision of the document for validation + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal>If-Match</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry>Current revision of the document for validation</entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry></entry><entry></entry></row></tbody></tgroup></informaltable> + + <para> + Upload the supplied content as an attachment to the specified + design document (<literal>/_design/design-doc</literal>). The + <literal>attachment</literal> name provided must be a URL encoded + string. You must also supply either the <literal>rev</literal> + query argument or the <literal>If-Match</literal> HTTP header for + validation, and the HTTP headers (to set the attacment content + type). The content type is used when the attachment is requested + as the corresponding content-type in the returned document header. + </para> + + <para> + For example, you could upload a simple text document using the + following request: + </para> + +<programlisting> +PUT http://couchdb:5984/recipes/_design/recipes/view.css?rev=7-f7114d4d81124b223283f3e89eee043e +Content-Length: 39 +Content-Type: text/plain + +div.recipetitle { +font-weight: bold; +} + +</programlisting> + + <para> + Or by using the <literal>If-Match</literal> HTTP header: + </para> + +<programlisting> +PUT http://couchdb:5984/recipes/FishStew/basic +If-Match: 7-f7114d4d81124b223283f3e89eee043e +Content-Length: 39 +Content-Type: text/plain + +div.recipetitle { +font-weight: bold; +} + +</programlisting> + + <para> + The returned JSON contains the new document information: + </para> + +<programlisting> +{ + "id" : "_design/recipes" + "ok" : true, + "rev" : "8-cb2b7d94eeac76782a02396ba70dfbf5", +} +</programlisting> + + <note> + <para> + Uploading an attachment updates the corresponding document + revision. Revisions are tracked for the parent document, not + individual attachments. + </para> + </note> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-attachment_delete"> + + <title><literal>DELETE /db/_design/design-doc/attachment</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API DELETE /db/_design/design-doc/attachment</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>DELETE /db/_design/design-doc/attachment</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the deleted revision + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>rev</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Current revision of the document for validation + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal>If-Match</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry>Current revision of the document for validation</entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>409</entry><entry namest="info" nameend="addinfo"> + Supplied revision is incorrect or missing + </entry></row></tbody></tgroup></informaltable> + + <para> + Deletes the attachment <literal>attachment</literal> to the + specified <literal>_design/design-doc</literal>. You must supply + the <literal>rev</literal> argument with the current revision to + delete the attachment. + </para> + + <para> + For example to delete the attachment <literal>view.css</literal> + from the design document <literal>recipes</literal>: + </para> + +<programlisting> +DELETE http://couchdb:5984/recipes/_design/recipes/view.css?rev=9-3db559f13a845c7751d407404cdeaa4a + </programlisting> + + <para> + The returned JSON contains the updated revision information for + the parent document: + </para> + +<programlisting> +{ + "id" : "_design/recipes" + "ok" : true, + "rev" : "10-f3b15bb408961f8dcc3d86c7d3b54c4c", +} +</programlisting> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-info_get"> + + <title><literal>GET /db/_design/design-doc/_info</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_design/design-doc/_info</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /db/_design/design-doc/_info</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the design document information + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Obtains information about a given design document, including the + index, index size and current status of the design document and + associated index information. + </para> + + <para> + For example, to get the information for the + <literal>recipes</literal> design document: + </para> + +<programlisting> +GET http://couchdb:5984/recipes/_design/recipes/_info +Content-Type: application/json +</programlisting> + + <para> + This returns the following JSON structure: + </para> + +<programlisting> +{ + "name" : "recipes" + "view_index" : { + "compact_running" : false, + "updater_running" : false, + "language" : "javascript", + "purge_seq" : 10, + "waiting_commit" : false, + "waiting_clients" : 0, + "signature" : "fc65594ee76087a3b8c726caf5b40687", + "update_seq" : 375031, + "disk_size" : 16491 + }, +} +</programlisting> + + <para> + The individual fields in the returned JSON structure are detailed + in + <xref linkend="table-couchdb-api-design_db-designdoc-info-json"/>. + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-design_db-designdoc-info-json" class="jsonstructure"><title>Design Document Info JSON Contents</title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>name</literal> </entry><entry> + Name/ID of Design Document + </entry></row><row><entry ><literal>view_index</literal> </entry><entry> + View Index + </entry></row><row><entry > <literal>compact_running</literal> </entry><entry> + Indicates whether a compaction routine is currently running on + the view + </entry></row><row><entry > <literal>disk_size</literal> </entry><entry> + Size in bytes of the view as stored on disk + </entry></row><row><entry > <literal>language</literal> </entry><entry> + Language for the defined views + </entry></row><row><entry > <literal>purge_seq</literal> </entry><entry> + The purge sequence that has been processed + </entry></row><row><entry > <literal>signature</literal> </entry><entry> + MD5 signature of the views for the design document + </entry></row><row><entry > <literal>update_seq</literal> </entry><entry> + The update sequence of the corresponding database that has been + indexed + </entry></row><row><entry > <literal>updater_running</literal> </entry><entry> + Indicates if the view is currently being updated + </entry></row><row><entry > <literal>waiting_clients</literal> </entry><entry> + Number of clients waiting on views from this design document + </entry></row><row><entry > <literal>waiting_commit</literal> </entry><entry> + Indicates if there are outstanding commits to the underlying + database that need to processed + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-view-viewname_get"> + + <title><literal>GET /db/_design/design-doc/_view/view-name</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_design/design-doc/_view/view-name</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /db/_design/design-doc/_view/view-name</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the documents returned by the view + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>descending</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return the documents in descending by key order + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>endkey</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Stop returning records when the specified key is reached + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>endkey_docid</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Stop returning records when the specified document ID is + reached + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>group</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Group the results using the reduce function to a group or + single row + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>group_level</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specify the group level to be used + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>include_docs</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Include the full content of the documents in the return + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>inclusive_end</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specifies whether the specified end key should be included + in the result + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>true</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>key</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return only documents that match the specified key + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>limit</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Limit the number of the returned documents to the specified + number + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>reduce</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Use the reduction function + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>true</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>skip</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Skip this number of records before starting to return the + results + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>0</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>stale</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Allow the results from a stale view to be used + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry></entry><entry><literal>ok</literal></entry><entry>Allow stale views</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>startkey</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return records starting with the specified key + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>startkey_docid</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return records starting with the specified document ID + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>update_seq</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Include the update sequence in the generated results + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row></tbody></tgroup></informaltable> + + <para> + Executes the specified <literal>view-name</literal> from the + specified <literal>design-doc</literal> design document. + </para> + + <section + id="couchdb-api-design_db-design-designdoc-view-viewname_get-indexes"> + + <title>Querying Views and Indexes</title> + + <para> + The definition of a view within a design document also creates + an index based on the key information defined within each view. + The production and use of the index significantly increases the + speed of access and searching or selecting documents from the + view. + </para> + + <para> + However, the index is not updated when new documents are added + or modified in the database. Instead, the index is generated or + updated, either when the view is first accessed, or when the + view is accessed after a document has been updated. In each + case, the index is updated before the view query is executed + against the database. + </para> + + <para> + View indexes are updated incrementally in the following + situations: + </para> + + <itemizedlist> + + <listitem> + <para> + A new document has been added to the database. + </para> + </listitem> + + <listitem> + <para> + A document has been deleted from the database. + </para> + </listitem> + + <listitem> + <para> + A document in the database has been updated. + </para> + </listitem> + + </itemizedlist> + + <para> + View indexes are rebuilt entirely when the view definition + changes. To achieve this, a 'fingerprint' of the view definition + is created when the design document is updated. If the + fingerprint changes, then the view indexes are entirely rebuilt. + This ensures that changes to the view definitions are reflected + in the view indexes. + </para> + + <note> + <para> + View index rebuilds occur when one view from the same the view + group (i.e. all the views defined within a single a design + document) has been determined as needing a rebuild. For + example, if if you have a design document with different + views, and you update the database, all three view indexes + within the design document will be updated. + </para> + </note> + + <para> + Because the view is updated when it has been queried, it can + result in a delay in returned information when the view is + accessed, especially if there are a large number of documents in + the database and the view index does not exist. There are a + number of ways to mitigate, but not completely eliminate, these + issues. These include: + </para> + + <itemizedlist> + + <listitem> + <para> + Create the view definition (and associated design documents) + on your database before allowing insertion or updates to the + documents. If this is allowed while the view is being + accessed, the index can be updated incrementally. + </para> + </listitem> + + <listitem> + <para> + Manually force a view request from the database. You can do + this either before users are allowed to use the view, or you + can access the view manually after documents are added or + updated. + </para> + </listitem> + + <listitem> + <para> + Use the <literal>/db/_changes</literal> method to monitor + for changes to the database and then access the view to + force the corresponding view index to be updated. See + <xref + linkend="couchdb-api-db_db-changes_get"/> + for more information. + </para> + </listitem> + + <listitem> + <para> + Use a monitor with the + <literal>update_notification</literal> section of the + CouchDB configuration file to monitor for changes to your + database, and trigger a view query to force the view to be + updated. For more information, see + <xref + linkend="couchdb-single-configuration-update_notification"/>. + </para> + </listitem> + + </itemizedlist> + + <para> + None of these can completely eliminate the need for the indexes + to be rebuilt or updated when the view is accessed, but they may + lessen the effects on end-users of the index update affecting + the user experience. + </para> + + <para> + Another alternative is to allow users to access a 'stale' + version of the view index, rather than forcing the index to be + updated and displaying the updated results. Using a stale view + may not return the latest information, but will return the + results of the view query using an existing version of the + index. + </para> + + <para> + For example, to access the existing stale view + <literal>by_recipe</literal> in the <literal>recipes</literal> + design document: + </para> + +<programlisting>http://couchdb:5984/recipes/_design/recipes/_view/by_recipe?stale=ok</programlisting> + + <para> + Accessing a stale view: + </para> + + <itemizedlist> + + <listitem> + <para> + Does not trigger a rebuild of the view indexes, even if + there have been changes since the last access. + </para> + </listitem> + + <listitem> + <para> + Returns the current version of the view index, if a current + version exists. + </para> + </listitem> + + <listitem> + <para> + Returns an empty result set if the given view index does + exist. + </para> + </listitem> + + </itemizedlist> + + <para> + As an alternative, you use the <literal>update_after</literal> + value to the <option>stale</option> paramater. This causes the + view to be returned as a stale view, but for the update process + to be triggered after the view information has been returned to + the client. + </para> + + <para> + In addition to using stale views, you can also make use of the + <literal>update_seq</literal> query argument. Using this query + argument generates the view information including the update + sequence of the database from which the view was generated. The + returned value can be compared this to the current update + sequence exposed in the database information (returned by + <xref linkend="couchdb-api-db_db_get"/>). + </para> + + </section> + + <section + id="couchdb-api-design_db-design-designdoc-view-viewname_get-sorting"> + + <title>Sorting Returned Rows</title> + + <para> + Each element within the returned array is sorted using native + UTF-8 sorting according to the contents of the key portion of + the emitted content. The basic order of output is as follows: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal>null</literal> + </para> + </listitem> + + <listitem> + <para> + <literal>false</literal> + </para> + </listitem> + + <listitem> + <para> + <literal>true</literal> + </para> + </listitem> + + <listitem> + <para> + Numbers + </para> + </listitem> + + <listitem> + <para> + Text (case sensitive, lowercase first) + </para> + </listitem> + + <listitem> + <para> + Arrays (according to the values of each element, in order) + </para> + </listitem> + + <listitem> + <para> + Objects (according to the values of keys, in key order) + </para> + </listitem> + + </itemizedlist> + + + + <para> + You can reverse the order of the returned view information by + using the <literal>descending</literal> query value set to true. + For example, Retrieving the list of recipes using the + <literal>by_title</literal> (limited to 5 records) view: + </para> + +<programlisting> +{ + "offset" : 0, + "rows" : [ + { + "id" : "3-tiersalmonspinachandavocadoterrine", + "key" : "3-tier salmon, spinach and avocado terrine", + "value" : [ + null, + "3-tier salmon, spinach and avocado terrine" + ] + }, + { + "id" : "Aberffrawcake", + "key" : "Aberffraw cake", + "value" : [ + null, + "Aberffraw cake" + ] + }, + { + "id" : "Adukiandorangecasserole-microwave", + "key" : "Aduki and orange casserole - microwave", + "value" : [ + null, + "Aduki and orange casserole - microwave" + ] + }, + { + "id" : "Aioli-garlicmayonnaise", + "key" : "Aioli - garlic mayonnaise", + "value" : [ + null, + "Aioli - garlic mayonnaise" + ] + }, + { + "id" : "Alabamapeanutchicken", + "key" : "Alabama peanut chicken", + "value" : [ + null, + "Alabama peanut chicken" + ] + } + ], + "total_rows" : 2667 +} +</programlisting> + + <para> + Requesting the same in descending order will reverse the entire + view content. For example the request + </para> + +<programlisting> +GET http://couchdb:5984/recipes/_design/recipes/_view/by_title?limit=5&descending=true +Accept: application/json +Content-Type: application/json</programlisting> + + <para> + Returns the last 5 records from the view: + </para> + +<programlisting> +{ + "offset" : 0, + "rows" : [ + { + "id" : "Zucchiniinagrodolcesweet-sourcourgettes", + "key" : "Zucchini in agrodolce (sweet-sour courgettes)", + "value" : [ + null, + "Zucchini in agrodolce (sweet-sour courgettes)" + ] + }, + { + "id" : "Zingylemontart", + "key" : "Zingy lemon tart", + "value" : [ + null, + "Zingy lemon tart" + ] + }, + { + "id" : "Zestyseafoodavocado", + "key" : "Zesty seafood avocado", + "value" : [ + null, + "Zesty seafood avocado" + ] + }, + { + "id" : "Zabaglione", + "key" : "Zabaglione", + "value" : [ + null, + "Zabaglione" + ] + }, + { + "id" : "Yogurtraita", + "key" : "Yogurt raita", + "value" : [ + null, + "Yogurt raita" + ] + } + ], + "total_rows" : 2667 +} +</programlisting> + + <para> + The sorting direction is applied before the filtering applied + using the <literal>startkey</literal> and + <literal>endkey</literal> query arguments. For example the + following query: + </para> + +<programlisting> +GET http://couchdb:5984/recipes/_design/recipes/_view/by_ingredient?startkey=%22carrots%22&endkey=%22egg%22 +Accept: application/json +Content-Type: application/json +</programlisting> + + <para> + Will operate correctly when listing all the matching entries + between <quote>carrots</quote> and <literal>egg</literal>. If + the order of output is reversed with the + <literal>descending</literal> query argument, the view request + will return no entries: + </para> + +<programlisting> +GET http://couchdb:5984/recipes/_design/recipes/_view/by_ingredient?descending=true&startkey=%22carrots%22&endkey=%22egg%22 +Accept: application/json +Content-Type: application/json +</programlisting> + + <para> + The returned result is empty: + </para> + +<programlisting> +{ + "total_rows" : 26453, + "rows" : [], + "offset" : 21882 +} +</programlisting> + + <para> + The results will be empty because the entries in the view are + reversed before the key filter is applied, and therefore the + <literal>endkey</literal> of <quote>egg</quote> will be seen + before the <literal>startkey</literal> of + <quote>carrots</quote>, resulting in an empty list. + </para> + + <para> + Instead, you should reverse the values supplied to the + <literal>startkey</literal> and <literal>endkey</literal> + parameters to match the descending sorting applied to the keys. + Changing the previous example to: + </para> + +<programlisting> +GET http://couchdb:5984/recipes/_design/recipes/_view/by_ingredient?descending=true&startkey=%22egg%22&endkey=%22carrots%22 +Accept: application/json +Content-Type: application/json +</programlisting> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-view-viewname_get-ranges"> + + <title>Specifying Start and End Values</title> + + <para> + The <literal>startkey</literal> and <literal>endkey</literal> + query arguments can be used to specify the range of values to be + displayed when querying the view. + </para> + + <note> + <para> + The values + </para> + </note> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-view-viewname_get-limit"> + + <title>Using Limits and Skipping Rows</title> + + <para> + TBC + </para> + + </section> + + <section + id="couchdb-api-design_db-design-designdoc-view-viewname_get-reduction"> + + <title>View Reduction and Grouping</title> + + <para> + TBC + </para> + + </section> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-view-viewname_post"> + + <title><literal>POST /db/_design/design-doc/_view/view-name</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_design/design-doc/_view/view-name</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>POST /db/_design/design-doc/_view/view-name</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + List of keys to be returned from specified view + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the documents returned by the view + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>descending</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return the documents in descending by key order + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>endkey</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Stop returning records when the specified key is reached + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>endkey_docid</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Stop returning records when the specified document ID is + reached + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>group</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Group the results using the reduce function to a group or + single row + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>group_level</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specify the group level to be used + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>include_docs</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Include the full content of the documents in the return + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>inclusive_end</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specifies whether the specified end key should be included + in the result + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>true</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>key</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return only documents that match the specified key + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>limit</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Limit the number of the returned documents to the specified + number + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>reduce</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Use the reduction function + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>true</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>skip</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Skip this number of records before starting to return the + results + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>0</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>stale</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Allow the results from a stale view to be used + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry></entry><entry><literal>ok</literal></entry><entry>Allow stale views</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>startkey</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return records starting with the specified key + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>startkey_docid</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return records starting with the specified document ID + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>update_seq</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Include the update sequence in the generated results + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>false</entry></row></tbody></tgroup></informaltable> + + <para> + Executes the specified <literal>view-name</literal> from the + specified <literal>design-doc</literal> design document. Unlike + the <literal>GET</literal> method for accessing views, the + <literal>POST</literal> method supports the specification of + explicit keys to be retrieved from the view results. The remainder + of the <literal>POST</literal> view functionality is identical to + the + <xref + linkend="couchdb-api-design_db-design-designdoc-view-viewname_get"/> + fun + </para> + + <para> + For example, the request below will return all the recipes where + the key for the view matches either <quote>claret</quote> or + <quote>clear apple cider</quote> : + </para> + +<programlisting> +POST http://couchdb:5984/recipes/_design/recipes/_view/by_ingredient +Content-Type: application/json + +{ + "keys" : [ + "claret", + "clear apple juice" + ] +} + </programlisting> + + <para> + The returned view data contains the standard view information, but + only where the keys match. + </para> + +<programlisting> +{ + "total_rows" : 26484, + "rows" : [ + { + "value" : [ + "Scotch collops" + ], + "id" : "Scotchcollops", + "key" : "claret" + }, + { + "value" : [ + "Stand pie" + ], + "id" : "Standpie", + "key" : "clear apple juice" + } + ], + "offset" : 6324 +} +</programlisting> + + <section + id="couchdb-api-design_db-design-designdoc-view-viewname_post-multidoc"> + + <title>Multi-document Fetching</title> + + <para> + By combining the <literal>POST</literal> method to a given view + with the <literal>include_docs=true</literal> query argument you + can obtain multiple documents from a database. The result is + more efficient than using multiple + <xref + linkend="couchdb-api-dbdoc_db-doc_get"/> + requests. + </para> + + <para> + For example, sending the following request for ingredients + matching <quote>claret</quote> and <quote>clear apple + juice</quote>: + </para> + +<programlisting> +POST http://couchdb:5984/recipes/_design/recipes/_view/by_ingredient?include_docs=true +Content-Type: application/json + +{ + "keys" : [ + "claret", + "clear apple juice" + ] +} +</programlisting> + + <para> + Returns the full document for each recipe: + </para> + +<programlisting> +{ + "offset" : 6324, + "rows" : [ + { + "doc" : { + "_id" : "Scotchcollops", + "_rev" : "1-bcbdf724f8544c89697a1cbc4b9f0178", + "cooktime" : "8", + "ingredients" : [ + { + "ingredient" : "onion", + "ingredtext" : "onion, peeled and chopped", + "meastext" : "1" + }, + ... + ], + "keywords" : [ + "cook method.hob, oven, grill@hob", + "diet@wheat-free", + "diet@peanut-free", + "special collections@classic recipe", + "cuisine@british traditional", + "diet@corn-free", + "diet@citrus-free", + "special collections@very easy", + "diet@shellfish-free", + "main ingredient@meat", + "occasion@christmas", + "meal type@main", + "diet@egg-free", + "diet@gluten-free" + ], + "preptime" : "10", + "servings" : "4", + "subtitle" : "This recipe comes from an old recipe book of 1683 called 'The Gentlewoman's Kitchen'. This is an excellent way of making a rich and full-flavoured meat dish in a very short time.", + "title" : "Scotch collops", + "totaltime" : "18" + }, + "id" : "Scotchcollops", + "key" : "claret", + "value" : [ + "Scotch collops" + ] + }, + { + "doc" : { + "_id" : "Standpie", + "_rev" : "1-bff6edf3ca2474a243023f2dad432a5a", + "cooktime" : "92", + "ingredients" : [ +... ], + "keywords" : [ + "diet@dairy-free", + "diet@peanut-free", + "special collections@classic recipe", + "cuisine@british traditional", + "diet@corn-free", + "diet@citrus-free", + "occasion@buffet party", + "diet@shellfish-free", + "occasion@picnic", + "special collections@lunchbox", + "main ingredient@meat", + "convenience@serve with salad for complete meal", + "meal type@main", + "cook method.hob, oven, grill@hob / oven", + "diet@cow dairy-free" + ], + "preptime" : "30", + "servings" : "6", + "subtitle" : "Serve this pie with pickled vegetables and potato salad.", + "title" : "Stand pie", + "totaltime" : "437" + }, + "id" : "Standpie", + "key" : "clear apple juice", + "value" : [ + "Stand pie" + ] + } + ], + "total_rows" : 26484 +} +</programlisting> + + </section> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-show-showname_get"> + + <title><literal>POST /db/_design/design-doc/_show/show-name</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_design/design-doc/_show/show-name</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /db/_design/design-doc/_show/show-name</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Returns the result of the show + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>details</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Indicates whether details should be included + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>format</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Format of the returned information + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row></tbody></tgroup></informaltable> + + <para></para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-show-showname-doc_get"> + + <title><literal>POST /db/_design/design-doc/_show/show-name/doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_design/design-doc/_show/show-name/doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /db/_design/design-doc/_show/show-name/doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Returns the show for the given document + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para></para> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-list-listname-otherdesigndoc-viewname_get"> + + <title><literal>GET + /db/_design/design-doc/_list/list-name/other-design-doc/view-name</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_design/design-doc/_list/list-name/other-design-doc/view-name</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /db/_design/design-doc/_list/list-name/other-design-doc/view-name</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + TBC + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + TBC + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-list-listname-otherdesigndoc-viewname_post"> + + <title><literal>POST + /db/_design/design-doc/_list/list-name/other-design-doc/view-name</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_design/design-doc/_list/list-name/other-design-doc/view-name</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>POST /db/_design/design-doc/_list/list-name/other-design-doc/view-name</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + TBC + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + TBC + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-list-listname-viewname_get"> + + <title><literal>GET /db/_design/design-doc/_list/list-name/view-name</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_design/design-doc/_list/list-name/view-name</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /db/_design/design-doc/_list/list-name/view-name</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + TBC + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + TBC + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-list-listname-viewname_post"> + + <title><literal>POST /db/_design/design-doc/_list/list-name/view-name</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_design/design-doc/_list/list-name/view-name</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>POST /db/_design/design-doc/_list/list-name/view-name</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + TBC + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + TBC + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + </section> + + <section id="couchdb-api-design_db-design-designdoc-update-updatename-doc_put"> + + <title><literal>PUT /db/_design/design-doc/_update/updatename/doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API PUT /db/_design/design-doc/_update/update-name/doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>PUT /db/_design/design-doc/_update/update-name/doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + Document update information + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Updated document + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + </section> + + <section + id="couchdb-api-design_db-design-designdoc-update-updatename_post"> + + <title><literal>POST /db/_design/design-doc/_update/updatename</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API POST /db/_design/design-doc/_update/update-name</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>POST /db/_design/design-doc/_update/update-name</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + Document update information + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Updated document + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + </section> + + <section + id="couchdb-api-design_db-design-designdoc-rewrite-rewritename-anything"> + + <title><literal>ALL + /db/_design/design-doc/_rewrite/rewrite-name/anything</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API ALL /db/_design/design-doc/_rewrite/rewrite-name/anything</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>ALL /db/_design/design-doc/_rewrite/rewrite-name/anything</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + TBC + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + TBC + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + </section> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-json.xml b/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-json.xml new file mode 100644 index 000000000..6e773d481 --- /dev/null +++ b/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-json.xml @@ -0,0 +1,347 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE appendix PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<appendix id="couchdb-api-json"> + + <title>JSON Structure Reference</title> + + <para> + The following appendix provides a quick reference to all the JSON + structures that you can supply to CouchDB, or get in return to + requests. + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-json-summary"><title>JSON Structures</title><tgroup cols="1"><colspec colname="desc"/><thead><row><entry>Description</entry></row></thead><tbody><row><entry><link linkend="table-couchdb-api-json_all-docs"> + All Database Documents + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_bulkdocsreturn"> + Bulk Document Response + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_bulkdocs"> + Bulk Documents + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_changes"> + Changes information for a database + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_document"> + CouchDB Document + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_jsonerror"> + CouchDB Error Status + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_db-info"> + CouchDB database information object + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_design-doc"> + Design Document + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_design-doc_info"> + Design Document Information + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_design-doc_info-spatial"> + Design Document spatial index Information + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_document_with_attachments"> + Document with Attachments + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_activetasks"> + List of Active Tasks + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_replication"> + Replication Settings + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_replication-status"> + Replication Status + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_document_with_revs_info"> + Returned CouchDB Document with Detailed Revision Info + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_document_with_revs"> + Returned CouchDB Document with Revision Info + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_returneddocument_with_attachments"> + Returned Document with Attachments + </link></entry></row><row><entry><link linkend="table-couchdb-api-json_security"> + Security Object + </link></entry></row></tbody></tgroup></table> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-json_all-docs" class="jsonstructure"><title> + All Database Documents + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>offset</literal> </entry><entry> + Offset where the document list started + </entry></row><row><entry ><literal>rows</literal> <literal>[array]</literal> </entry><entry> + Array of document object + </entry></row><row><entry ><literal>total_rows</literal> </entry><entry> + Number of documents in the database/view + </entry></row><row><entry ><literal>update_seq</literal> (optional) </entry><entry> + Current update sequence for the database + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_bulkdocsreturn" class="jsonstructure"><title> + Bulk Document Response + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>docs</literal> <literal>[array]</literal> </entry><entry> + Bulk Docs Returned Documents + </entry></row><row><entry > <literal>error</literal> </entry><entry> + Error type + </entry></row><row><entry > <literal>id</literal> </entry><entry> + Document ID + </entry></row><row><entry > <literal>reason</literal> </entry><entry> + Error string with extended reason + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_bulkdocs" class="jsonstructure"><title> + Bulk Documents + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>all_or_nothing</literal> (optional) </entry><entry> + Sets the database commit mode to use all-or-nothing semantics + </entry></row><row><entry ><literal>docs</literal> <literal>[array]</literal> </entry><entry> + Bulk Documents Document + </entry></row><row><entry > <literal>_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry > <literal>_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row><row><entry > <literal>_deleted</literal> (optional) </entry><entry> + Whether the document should be deleted + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_changes" class="jsonstructure"><title> + Changes information for a database + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>last_seq</literal> </entry><entry> + Last change sequence number + </entry></row><row><entry ><literal>results</literal> <literal>[array]</literal> </entry><entry> + Changes made to a database + </entry></row><row><entry > <literal>changes</literal> <literal>[array]</literal> </entry><entry> + List of changes, field-by-field, for this document + </entry></row><row><entry > <literal>id</literal> </entry><entry> + Document ID + </entry></row><row><entry > <literal>seq</literal> </entry><entry> + Update sequence number + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_document" class="jsonstructure"><title> + CouchDB Document + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry ><literal>_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_jsonerror" class="jsonstructure"><title> + CouchDB Error Status + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>error</literal> </entry><entry> + Error type + </entry></row><row><entry ><literal>id</literal> </entry><entry> + Document ID + </entry></row><row><entry ><literal>reason</literal> </entry><entry> + Error string with extended reason + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_db-info" class="jsonstructure"><title> + CouchDB database information object + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>committed_update_seq</literal> </entry><entry> + The number of committed update. + </entry></row><row><entry ><literal>compact_running</literal> </entry><entry> + Set to true if the database compaction routine is operating on + this database. + </entry></row><row><entry ><literal>db_name</literal> </entry><entry> + The name of the database. + </entry></row><row><entry ><literal>disk_format_version</literal> </entry><entry> + The version of the physical format used for the data when it is + stored on disk. + </entry></row><row><entry ><literal>disk_size</literal> </entry><entry> + Size in bytes of the data as stored on the disk. Views indexes + are not included in the calculation. + </entry></row><row><entry ><literal>doc_count</literal> </entry><entry> + A count of the documents in the specified database. + </entry></row><row><entry ><literal>doc_del_count</literal> </entry><entry> + Number of deleted documents + </entry></row><row><entry ><literal>instance_start_time</literal> </entry><entry> + Timestamp of when the database was created, expressed in + milliseconds since the epoch. + </entry></row><row><entry ><literal>purge_seq</literal> </entry><entry> + The number of purge operations on the database. + </entry></row><row><entry ><literal>update_seq</literal> </entry><entry> + The current number of updates to the database. + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_design-doc" class="jsonstructure"><title> + Design Document + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>_id</literal> </entry><entry> + Design Document ID + </entry></row><row><entry ><literal>_rev</literal> </entry><entry> + Design Document Revision + </entry></row><row><entry ><literal>views</literal> </entry><entry> + View + </entry></row><row><entry > <literal>viewname</literal> </entry><entry> + View Definition + </entry></row><row><entry > <literal>map</literal> </entry><entry> + Map Function for View + </entry></row><row><entry > <literal>reduce</literal> (optional) </entry><entry> + Reduce Function for View + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_design-doc_info" class="jsonstructure"><title> + Design Document Information + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>name</literal> </entry><entry> + Name/ID of Design Document + </entry></row><row><entry ><literal>view_index</literal> </entry><entry> + View Index + </entry></row><row><entry > <literal>compact_running</literal> </entry><entry> + Indicates whether a compaction routine is currently running on + the view + </entry></row><row><entry > <literal>disk_size</literal> </entry><entry> + Size in bytes of the view as stored on disk + </entry></row><row><entry > <literal>language</literal> </entry><entry> + Language for the defined views + </entry></row><row><entry > <literal>purge_seq</literal> </entry><entry> + The purge sequence that has been processed + </entry></row><row><entry > <literal>signature</literal> </entry><entry> + MD5 signature of the views for the design document + </entry></row><row><entry > <literal>update_seq</literal> </entry><entry> + The update sequence of the corresponding database that has been + indexed + </entry></row><row><entry > <literal>updater_running</literal> </entry><entry> + Indicates if the view is currently being updated + </entry></row><row><entry > <literal>waiting_clients</literal> </entry><entry> + Number of clients waiting on views from this design document + </entry></row><row><entry > <literal>waiting_commit</literal> </entry><entry> + Indicates if there are outstanding commits to the underlying + database that need to processed + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_design-doc_info-spatial" class="jsonstructure"><title> + Design Document spatial index Information + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>name</literal> </entry><entry> + Name/ID of Design Document + </entry></row><row><entry ><literal>spatial_index</literal> </entry><entry> + View Index + </entry></row><row><entry > <literal>compact_running</literal> </entry><entry> + Indicates whether a compaction routine is currently running on + the view + </entry></row><row><entry > <literal>disk_size</literal> </entry><entry> + Size in bytes of the view as stored on disk + </entry></row><row><entry > <literal>language</literal> </entry><entry> + Language for the defined views + </entry></row><row><entry > <literal>purge_seq</literal> </entry><entry> + The purge sequence that has been processed + </entry></row><row><entry > <literal>signature</literal> </entry><entry> + MD5 signature of the views for the design document + </entry></row><row><entry > <literal>update_seq</literal> </entry><entry> + The update sequence of the corresponding database that has been + indexed + </entry></row><row><entry > <literal>updater_running</literal> </entry><entry> + Indicates if the view is currently being updated + </entry></row><row><entry > <literal>waiting_clients</literal> </entry><entry> + Number of clients waiting on views from this design document + </entry></row><row><entry > <literal>waiting_commit</literal> </entry><entry> + Indicates if there are outstanding commits to the underlying + database that need to processed + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_document_with_attachments" class="jsonstructure"><title> + Document with Attachments + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry ><literal>_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row><row><entry ><literal>_attachments</literal> (optional) </entry><entry> + Document Attachment + </entry></row><row><entry > <literal>filename</literal> </entry><entry> + Attachment information + </entry></row><row><entry > <literal>content_type</literal> </entry><entry> + MIME Content type string + </entry></row><row><entry > <literal>data</literal> </entry><entry> + File attachment content, Base64 encoded + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_activetasks" class="jsonstructure"><title> + List of Active Tasks + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>tasks</literal> <literal>[array]</literal> </entry><entry> + Active Task + </entry></row><row><entry > <literal>pid</literal> </entry><entry> + Process ID + </entry></row><row><entry > <literal>status</literal> </entry><entry> + Task status message + </entry></row><row><entry > <literal>task</literal> </entry><entry> + Task name + </entry></row><row><entry > <literal>type</literal> </entry><entry> + Operation Type + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_replication" class="jsonstructure"><title> + Replication Settings + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>cancel</literal> (optional) </entry><entry> + Cancels the replication + </entry></row><row><entry ><literal>continuous</literal> (optional) </entry><entry> + Configure the replication to be continuous + </entry></row><row><entry ><literal>create_target</literal> (optional) </entry><entry> + Creates the target database + </entry></row><row><entry ><literal>doc_ids</literal> (optional) </entry><entry> + Array of document IDs to be synchronized + </entry></row><row><entry ><literal>proxy</literal> (optional) </entry><entry> + Address of a proxy server through which replication should occur + </entry></row><row><entry ><literal>source</literal> </entry><entry> + Source database name or URL + </entry></row><row><entry ><literal>target</literal> </entry><entry> + Target database name or URL + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_replication-status" class="jsonstructure"><title> + Replication Status + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>history</literal> <literal>[array]</literal> </entry><entry> + Replication History + </entry></row><row><entry > <literal>doc_write_failures</literal> </entry><entry> + Number of document write failures + </entry></row><row><entry > <literal>docs_read</literal> </entry><entry> + Number of documents read + </entry></row><row><entry > <literal>docs_written</literal> </entry><entry> + Number of documents written to target + </entry></row><row><entry > <literal>end_last_seq</literal> </entry><entry> + Last sequence number in changes stream + </entry></row><row><entry > <literal>end_time</literal> </entry><entry> + Date/Time replication operation completed + </entry></row><row><entry > <literal>missing_checked</literal> </entry><entry> + Number of missing documents checked + </entry></row><row><entry > <literal>missing_found</literal> </entry><entry> + Number of missing documents found + </entry></row><row><entry > <literal>recorded_seq</literal> </entry><entry> + Last recorded sequence number + </entry></row><row><entry > <literal>session_id</literal> </entry><entry> + Session ID for this replication operation + </entry></row><row><entry > <literal>start_last_seq</literal> </entry><entry> + First sequence number in changes stream + </entry></row><row><entry > <literal>start_time</literal> </entry><entry> + Date/Time replication operation started + </entry></row><row><entry ><literal>ok</literal> </entry><entry> + Replication status + </entry></row><row><entry ><literal>session_id</literal> </entry><entry> + Unique session ID + </entry></row><row><entry ><literal>source_last_seq</literal> </entry><entry> + Last sequence number read from source database + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_document_with_revs_info" class="jsonstructure"><title> + Returned CouchDB Document with Detailed Revision Info + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry ><literal>_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row><row><entry ><literal>_revs_info</literal> <literal>[array]</literal> </entry><entry> + CouchDB Document Extended Revision Info + </entry></row><row><entry > <literal>rev</literal> </entry><entry> + Full revision string + </entry></row><row><entry > <literal>status</literal> </entry><entry> + Status of the revision + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_document_with_revs" class="jsonstructure"><title> + Returned CouchDB Document with Revision Info + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry ><literal>_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row><row><entry ><literal>_revisions</literal> </entry><entry> + CouchDB Document Revisions + </entry></row><row><entry > <literal>ids</literal> <literal>[array]</literal> </entry><entry> + Array of valid revision IDs, in reverse order (latest first) + </entry></row><row><entry > <literal>start</literal> </entry><entry> + Prefix number for the latest revision + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_returneddocument_with_attachments" class="jsonstructure"><title> + Returned Document with Attachments + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>_id</literal> (optional) </entry><entry> + Document ID + </entry></row><row><entry ><literal>_rev</literal> (optional) </entry><entry> + Revision ID (when updating an existing document) + </entry></row><row><entry ><literal>_attachments</literal> (optional) </entry><entry> + Document Attachment + </entry></row><row><entry > <literal>filename</literal> </entry><entry> + Attachment + </entry></row><row><entry > <literal>content_type</literal> </entry><entry> + MIME Content type string + </entry></row><row><entry > <literal>length</literal> </entry><entry> + Length (bytes) of the attachment data + </entry></row><row><entry > <literal>revpos</literal> </entry><entry> + Revision where this attachment exists + </entry></row><row><entry > <literal>stub</literal> </entry><entry> + Indicates whether the attachment is a stub + </entry></row></tbody></tgroup></table><table id="table-couchdb-api-json_security" class="jsonstructure"><title> + Security Object + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>admins</literal> </entry><entry> + Roles/Users with admin privileges + </entry></row><row><entry > <literal>roles</literal> <literal>[array]</literal> </entry><entry> + List of roles with parent privilege + </entry></row><row><entry > <literal>users</literal> <literal>[array]</literal> </entry><entry> + List of users with parent privilege + </entry></row><row><entry ><literal>readers</literal> </entry><entry> + Roles/Users with reader privileges + </entry></row><row><entry > <literal>roles</literal> <literal>[array]</literal> </entry><entry> + List of roles with parent privilege + </entry></row><row><entry > <literal>users</literal> <literal>[array]</literal> </entry><entry> + List of users with parent privilege + </entry></row></tbody></tgroup></table> + +</appendix> diff --git a/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-localdb.xml b/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-localdb.xml new file mode 100644 index 000000000..9f7161f14 --- /dev/null +++ b/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-localdb.xml @@ -0,0 +1,188 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-api-localdb"> + + <title>CouchDB API Server Local (non-replicating) Document Methods</title> + + <para> + The Local (non-replicating) document interface allows you to create + local documents that are not replicated to other databases. These + documents can be used to hold configuration or other information + that is required specifically on the local CouchDB instance. + </para> + + <para> + Local documents have the following limitations: + </para> + + <itemizedlist> + + <listitem> + <para> + Local documents are not replicated to other databases. + </para> + </listitem> + + <listitem> + <para> + The ID of the local document must be known for the document to + accessed. You cannot obtain a list of local documents from the + database. + </para> + </listitem> + + <listitem> + <para> + Local documents are not output by views, or the + <literal>_all_docs</literal> view. + </para> + </listitem> + + </itemizedlist> + + <para> + Local documents can be used when you want to store configuration or + other information for the curent (local) instance of a given + database. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-api-localdb-summary"><title>Local (non-replicating) Document API + Calls</title><tgroup cols="3"><colspec colname="method"/><colspec colname="path"/><colspec colname="desc"/><thead><row><entry>Method</entry><entry>Path</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>GET</literal></entry><entry><literal>/db/_local/local-doc</literal></entry><entry><link linkend="couchdb-api-localdb_db-local-localdoc_get"> + Returns the latest revision of the non-replicated document + </link></entry></row><row><entry><literal>PUT</literal></entry><entry><literal>/db/_local/local-doc</literal></entry><entry><link linkend="couchdb-api-localdb_db-local-localdoc_put"> + Inserts a new version of the non-replicated document + </link></entry></row><row><entry><literal>DELETE</literal></entry><entry><literal>/db/_local/local-doc</literal></entry><entry><link linkend="couchdb-api-localdb_db-local-localdoc_delete"> + Deletes the non-replicated document + </link></entry></row><row><entry><literal>COPY</literal></entry><entry><literal>/db/_local/local-doc</literal></entry><entry><link linkend="couchdb-api-localdb_db-local-localdoc_copy"> + Copies the non-replicated document + </link></entry></row></tbody></tgroup></table> + + <section id="couchdb-api-localdb_db-local-localdoc_get"> + + <title><literal>GET /db/_local/local-doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /db/_local/local-doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /db/_local/local-doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the returned document + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>rev</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Specify the revision to return + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry></entry><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry></entry><entry><literal>true</literal></entry><entry>Includes the revisions</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>revs</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return a list of the revisions for the document + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>revs_info</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Return a list of detailed revision information for the + document + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>boolean</entry></row><row><entry></entry><entry><emphasis role="bold">Supported Values</emphasis></entry></row><row><entry></entry><entry><literal>true</literal></entry><entry>Includes the revisions</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>400</entry><entry namest="info" nameend="addinfo"> + The format of the request or revision was invalid + </entry></row><row><entry>404</entry><entry namest="info" nameend="addinfo"> + The specified document or revision cannot be found, or has been + deleted + </entry></row></tbody></tgroup></informaltable> + + <para> + Gets the specified local document. The semantics are identical to + accessing a standard document in the specified database, except + that the document is not replicated. See + <xref + linkend="couchdb-api-dbdoc_db-doc_get"/>. + </para> + + </section> + + <section id="couchdb-api-localdb_db-local-localdoc_put"> + + <title><literal>PUT /db/_local/local-doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API PUT /db/_local/local-doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>PUT /db/_local/local-doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the document + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON with the committed document information + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>201</entry><entry namest="info" nameend="addinfo"> + Document has been created successfully + </entry></row></tbody></tgroup></informaltable> + + <para> + Stores the specified local document. The semantics are identical + to storing a standard document in the specified database, except + that the document is not replicated. See + <xref + linkend="couchdb-api-dbdoc_db-doc_put"/>. + </para> + + </section> + + <section id="couchdb-api-localdb_db-local-localdoc_delete"> + + <title><literal>DELETE /db/_local/local-doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API DELETE /db/_local/local-doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>DELETE /db/_local/local-doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON with the deleted document information + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>rev</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Current revision of the document for validation + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal>If-Match</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry>Current revision of the document for validation</entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>409</entry><entry namest="info" nameend="addinfo"> + Supplied revision is incorrect or missing + </entry></row></tbody></tgroup></informaltable> + + <para> + Deletes the specified local document. The semantics are identical + to deleting a standard document in the specified database, except + that the document is not replicated. See + <xref + linkend="couchdb-api-dbdoc_db-doc_delete"/>. + </para> + + </section> + + <section id="couchdb-api-localdb_db-local-localdoc_copy"> + + <title><literal>COPY /db/_local/local-doc</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API COPY /db/_local/local-doc</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>COPY /db/_local/local-doc</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON of the copied document + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>rev</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Revision to copy from + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>string</entry></row><row><entry><emphasis role="bold">HTTP Headers</emphasis></entry><entry><emphasis role="bold">Header</emphasis></entry><entry><literal>Destination</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry>Destination document (and optional revision)</entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>no</entry></row><row><entry></entry><entry></entry><entry></entry></row></tbody></tgroup></informaltable> + + <para> + Copies the specified local document. The semantics are identical + to copying a standard document in the specified database, except + that the document is not replicated. See + <xref + linkend="couchdb-api-dbdoc_db-doc_copy"/>. + </para> + + </section> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-misc.xml b/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-misc.xml new file mode 100644 index 000000000..a9ae88264 --- /dev/null +++ b/share/docs/couchdb-manual-1.1/metadoc-couchdb-api-misc.xml @@ -0,0 +1,1412 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE chapter PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<chapter id="couchdb-api-misc"> + + <title>CouchDB API Server Miscellaneous Methods</title> + + <para> + The CouchDB Miscellaneous interface provides the basic interface to + a CouchDB server for obtaining CouchDB information and getting and + setting configuration information. + </para> + + <para> + A list of the available methods and URL paths are provided below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-misc-summary"><title>Miscellaneous API Calls</title><tgroup cols="3"><colspec colname="method"/><colspec colname="path"/><colspec colname="desc"/><thead><row><entry>Method</entry><entry>Path</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>GET</literal></entry><entry><literal>/</literal></entry><entry><link linkend="couchdb-api-misc_root_get"> + Get the welcome message and version information + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/_active_tasks</literal></entry><entry><link linkend="couchdb-api-misc_active-tasks_get"> + Obtain a list of the tasks running in the server + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/_all_dbs</literal></entry><entry><link linkend="couchdb-api-misc_all-dbs_get"> + Get a list of all the DBs + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/_log</literal></entry><entry><link linkend="couchdb-api-misc_log_get"> + Return the server log file + </link></entry></row><row><entry><literal>POST</literal></entry><entry><literal>/_replicate</literal></entry><entry><link linkend="couchdb-api-misc_replicate_post"> + Set or cancel replication + </link></entry></row><row><entry><literal>POST</literal></entry><entry><literal>/_restart</literal></entry><entry><link linkend="couchdb-api-misc_restart_post"> + Restart the server + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/_stats</literal></entry><entry><link linkend="couchdb-api-misc_stats_get"> + Return server statistics + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/_utils</literal></entry><entry><link linkend="couchdb-api-misc_utils_get"> + CouchDB administration interface (Futon) + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/_uuids</literal></entry><entry><link linkend="couchdb-api-misc_uuids_get"> + Get generated UUIDs from the server + </link></entry></row><row><entry><literal>GET</literal></entry><entry><literal>/favicon.ico</literal></entry><entry><link linkend="couchdb-api-misc_favicon_get"> + Get the site icon + </link></entry></row></tbody></tgroup></table> + + <section id="couchdb-api-misc_root_get"> + + <title><literal>GET /</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Welcome message and version + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Request completed successfully. + </entry></row></tbody></tgroup></informaltable> + + <para> + Accessing the root of a CouchDB instance returns meta information + about the instance. The response is a JSON structure containing + information about the server, including a welcome message and the + version of the server. + </para> + +<programlisting> +{ + "couchdb" : "Welcome", + "version" : "1.0.1" +} +</programlisting> + + </section> + + <section id="couchdb-api-misc_active-tasks_get"> + + <title><literal>GET /_active_tasks</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /_active_tasks</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /_active_tasks</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + List of running tasks, including the task type, name, status and + process ID + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Request completed successfully. + </entry></row></tbody></tgroup></informaltable> + + <para> + You can obtain a list of active tasks by using the + <literal>/_active_tasks</literal> URL. The result is a JSON array + of the currently running tasks, with each task being described + with a single object. For example: + </para> + +<programlisting> + +<![CDATA[ +[ + { + "pid" : "<0.11599.0>", + "status" : "Copied 0 of 18369 changes (0%)", + "task" : "recipes", + "type" : "Database Compaction" + } +] +]]> + + </programlisting> + + <para> + The returned structure includes the following fields for each + task: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-misc-active-tasks-json" class="jsonstructure"><title> + List of Active Tasks + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>tasks</literal> <literal>[array]</literal> </entry><entry> + Active Task + </entry></row><row><entry > <literal>pid</literal> </entry><entry> + Process ID + </entry></row><row><entry > <literal>status</literal> </entry><entry> + Task status message + </entry></row><row><entry > <literal>task</literal> </entry><entry> + Task name + </entry></row><row><entry > <literal>type</literal> </entry><entry> + Operation Type + </entry></row></tbody></tgroup></table> + + <para> + For operation type, valid values include: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal>Database Compaction</literal> + </para> + </listitem> + + <listitem> + <para> + <literal>Replication</literal> + </para> + </listitem> + + <listitem> + <para> + <literal>View Group Compaction</literal> + </para> + </listitem> + + <listitem> + <para> + <literal>View Group Indexer</literal> + </para> + </listitem> + + </itemizedlist> + + </section> + + <section id="couchdb-api-misc_all-dbs_get"> + + <title><literal>GET /_all_dbs</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /_all_dbs</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /_all_dbs</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON list of DBs + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Request completed successfully. + </entry></row></tbody></tgroup></informaltable> + + <para> + Returns a list of all the databases in the CouchDB instance. For + example: + </para> + +<programlisting> +GET http://couchdb:5984/_all_dbs +Accept: application/json +</programlisting> + + <para> + The return is a JSON array: + </para> + +<programlisting> +[ + "_users", + "contacts", + "docs", + "invoices", + "locations" +] + +</programlisting> + + </section> + + <section id="couchdb-api-misc_log_get"> + + <title><literal>GET /_log</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API GET /_log</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /_log</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Log content + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>bytes</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Bytes to be returned + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>1000</entry></row><row><entry></entry><entry></entry><entry></entry></row><row><entry></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>offset</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Offset in bytes where the log tail should be started + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry></entry><entry><emphasis role="bold">Default</emphasis></entry><entry>0</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Request completed successfully. + </entry></row></tbody></tgroup></informaltable> + + <para> + Gets the CouchDB log, equivalent to accessing the local log file + of the corresponding CouchDB instance. + </para> + + <para> + When you request the log, the response is returned as plain + (UTF-8) text, with an HTTP <literal>Content-type</literal> header + as <literal>text/plain</literal>. + </para> + + <para> + For example, the request: + </para> + +<programlisting> +GET http://couchdb:5984/_log +Accept: */* +</programlisting> + + <para> + The raw text is returned: + </para> + +<programlisting> +<![CDATA[ +[Wed, 27 Oct 2010 10:49:42 GMT] [info] [<0.23338.2>] 192.168.0.2 - - 'PUT' /authdb 401 + +[Wed, 27 Oct 2010 11:02:19 GMT] [info] [<0.23428.2>] 192.168.0.116 - - 'GET' /recipes/FishStew 200 + +[Wed, 27 Oct 2010 11:02:19 GMT] [info] [<0.23428.2>] 192.168.0.116 - - 'GET' /_session 200 + +[Wed, 27 Oct 2010 11:02:19 GMT] [info] [<0.24199.2>] 192.168.0.116 - - 'GET' / 200 + +[Wed, 27 Oct 2010 13:03:38 GMT] [info] [<0.24207.2>] 192.168.0.116 - - 'GET' /_log?offset=5 200 +]]> +</programlisting> + + <para> + If you want to pick out specific parts of the log information you + can use the <literal>bytes</literal> argument, which specifies the + number of bytes to be returned, and <literal>offset</literal>, + which specifies where the reading of the log should start, counted + back from the end. For example, if you use the following request: + </para> + +<programlisting> +GET /_log?bytes=500&offset=2000 +</programlisting> + + <para> + Reading of the log will start at 2000 bytes from the end of the + log, and 500 bytes will be shown. + </para> + + </section> + + <section id="couchdb-api-misc_replicate_post"> + + <title><literal>POST /_replicate</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<informaltable><textobject><phrase>URL API POST /_replicate</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>POST /_replicate</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + Replication specification + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Welcome message and version + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Replication request successfully completed + </entry></row><row><entry>202</entry><entry namest="info" nameend="addinfo"> + Continuous replication request has been accepted + </entry></row><row><entry>404</entry><entry namest="info" nameend="addinfo"> + Either the source or target DB is not found + </entry></row><row><entry>500</entry><entry namest="info" nameend="addinfo"> + JSON specification was invalid + </entry></row></tbody></tgroup></informaltable> + + <para> + Request, configure, or stop, a replication operation. + </para> + + <para> + The specification of the replication request is controlled through + the JSON content of the request. The JSON should be an object with + the fields defining the source, target and other options. The + fields of the JSON request are shown in the table below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-misc-json-replication" class="jsonstructure"><title> + Replication Settings + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>cancel</literal> (optional) </entry><entry> + Cancels the replication + </entry></row><row><entry ><literal>continuous</literal> (optional) </entry><entry> + Configure the replication to be continuous + </entry></row><row><entry ><literal>create_target</literal> (optional) </entry><entry> + Creates the target database + </entry></row><row><entry ><literal>doc_ids</literal> (optional) </entry><entry> + Array of document IDs to be synchronized + </entry></row><row><entry ><literal>proxy</literal> (optional) </entry><entry> + Address of a proxy server through which replication should occur + </entry></row><row><entry ><literal>source</literal> </entry><entry> + Source database name or URL + </entry></row><row><entry ><literal>target</literal> </entry><entry> + Target database name or URL + </entry></row></tbody></tgroup></table> + + <section id="couchdb-api-misc_replicate_post-operation"> + + <title>Replication Operation</title> + + <para> + The aim of the replication is that at the end of the process, + all active documents on the source database are also in the + destination database and all documents that were deleted in the + source databases are also deleted (if they exist) on the + destination database. + </para> + + <para> + Replication can be described as either push or pull replication: + </para> + + <itemizedlist> + + <listitem> + <para> + <emphasis>Pull replication</emphasis> is where the + <literal>source</literal> is the remote CouchDB instance, + and the <literal>destination</literal> is the local + database. + </para> + + <para> + Pull replication is the most useful solution to use if your + source database has a permanent IP address, and your + destination (local) database may have a dynamically assigned + IP address (for example, through DHCP). This is particularly + important if you are replicating to a mobile or other device + from a central server. + </para> + </listitem> + + <listitem> + <para> + <emphasis>Push replication</emphasis> is where the + <literal>source</literal> is a local database, and + <literal>destination</literal> is a remote database. + </para> + </listitem> + + </itemizedlist> + + </section> + + <section id="couchdb-api-misc_replicate_post-sourcetarget"> + + <title>Specifying the Source and Target Database</title> + + <para> + You must use the URL specification of the CouchDB database if + you want to perform replication in either of the following two + situations: + </para> + + <itemizedlist> + + <listitem> + <para> + Replication with a remote database (i.e. another instance of + CouchDB on the same host, or a different host) + </para> + </listitem> + + <listitem> + <para> + Replication with a database that requires authentication + </para> + </listitem> + + </itemizedlist> + + <para> + For example, to request replication between a database local to + the CouchDB instance to which you send the request, and a remote + database you might use the following request: + </para> + +<programlisting> +POST http://couchdb:5984/_replicate +Content-Type: application/json +Accept: application/json + +{ + "source" : "recipes", + "target" : "http://coucdb-remote:5984/recipes", +} + </programlisting> + + <para> + In all cases, the requested databases in the + <literal>source</literal> and <literal>target</literal> + specification must exist. If they do not, an error will be + returned within the JSON object: + </para> + +<programlisting> +{ + "error" : "db_not_found" + "reason" : "could not open http://couchdb-remote:5984/ol1ka/", +} + </programlisting> + + <para> + You can create the target database (providing your user + credentials allow it) by adding the + <literal>create_target</literal> field to the request object: + </para> + +<programlisting> +POST http://couchdb:5984/_replicate +Content-Type: application/json +Accept: application/json + +{ + "create_target" : true + "source" : "recipes", + "target" : "http://couchdb-remote:5984/recipes", +} +</programlisting> + + <para> + The <literal>create_target</literal> field is not destructive. + If the database already exists, the replication proceeds as + normal. + </para> + + </section> + + <section id="couchdb-api-misc_replicate_post-single"> + + <title>Single Replication</title> + + <para> + You can request replication of a database so that the two + databases can be synchronized. By default, the replication + process occurs one time and synchronizes the two databases + together. For example, you can request a single synchronization + between two databases by supplying the <literal>source</literal> + and <literal>target</literal> fields within the request JSON + content. + </para> + +<programlisting> +POST http://couchdb:5984/_replicate +Content-Type: application/json +Accept: application/json + +{ + "source" : "recipes", + "target" : "recipes-snapshot", +} +</programlisting> + + <para> + In the above example, the databases <literal>recipes</literal> + and <literal>recipes-snapshot</literal> will be synchronized. + These databases are local to the CouchDB instance where the + request was made. The response will be a JSON structure + containing the success (or failure) of the synchronization + process, and statistics about the process: + </para> + +<programlisting> +{ + "ok" : true, + "history" : [ + { + "docs_read" : 1000, + "session_id" : "52c2370f5027043d286daca4de247db0", + "recorded_seq" : 1000, + "end_last_seq" : 1000, + "doc_write_failures" : 0, + "start_time" : "Thu, 28 Oct 2010 10:24:13 GMT", + "start_last_seq" : 0, + "end_time" : "Thu, 28 Oct 2010 10:24:14 GMT", + "missing_checked" : 0, + "docs_written" : 1000, + "missing_found" : 1000 + } + ], + "session_id" : "52c2370f5027043d286daca4de247db0", + "source_last_seq" : 1000 +} +</programlisting> + + <para> + The structure defines the replication status, as described in + the table below: + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/JSON/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//json/json.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/JSON.pm"/> +<table id="table-couchdb-api-misc-json-replication-status" class="jsonstructure"><title> + Replication Status + </title><tgroup cols="2"><colspec colname="item" colwidth="30*"/><colspec colname="desc" colwidth="70*"/><tbody><row><entry ><emphasis role="bold">Field</emphasis></entry><entry><emphasis role="bold">Description</emphasis></entry></row><row><entry ><literal>history</literal> <literal>[array]</literal> </entry><entry> + Replication History + </entry></row><row><entry > <literal>doc_write_failures</literal> </entry><entry> + Number of document write failures + </entry></row><row><entry > <literal>docs_read</literal> </entry><entry> + Number of documents read + </entry></row><row><entry > <literal>docs_written</literal> </entry><entry> + Number of documents written to target + </entry></row><row><entry > <literal>end_last_seq</literal> </entry><entry> + Last sequence number in changes stream + </entry></row><row><entry > <literal>end_time</literal> </entry><entry> + Date/Time replication operation completed + </entry></row><row><entry > <literal>missing_checked</literal> </entry><entry> + Number of missing documents checked + </entry></row><row><entry > <literal>missing_found</literal> </entry><entry> + Number of missing documents found + </entry></row><row><entry > <literal>recorded_seq</literal> </entry><entry> + Last recorded sequence number + </entry></row><row><entry > <literal>session_id</literal> </entry><entry> + Session ID for this replication operation + </entry></row><row><entry > <literal>start_last_seq</literal> </entry><entry> + First sequence number in changes stream + </entry></row><row><entry > <literal>start_time</literal> </entry><entry> + Date/Time replication operation started + </entry></row><row><entry ><literal>ok</literal> </entry><entry> + Replication status + </entry></row><row><entry ><literal>session_id</literal> </entry><entry> + Unique session ID + </entry></row><row><entry ><literal>source_last_seq</literal> </entry><entry> + Last sequence number read from source database + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-api-misc_replicate_post-continuous"> + + <title>Continuous Replication</title> + + <para> + Synchronization of a database with the previously noted methods + happens only once, at the time the replicate request is made. To + have the target database permanently replicated from the source, + you must set the <literal>continuous</literal> field of the JSON + object within the request to true. + </para> + + <para> + With continuous replication changes in the source database are + replicated to the target database in perpetuity until you + specifically request that replication ceases. + </para> + +<programlisting> +POST http://couchdb:5984/_replicate +Content-Type: application/json +Accept: application/json + +{ + "continuous" : true + "source" : "recipes", + "target" : "http://couchdb-remote:5984/recipes", +} +</programlisting> + + <para> + Changes will be replicated between the two databases as long as + a network connection is available between the two instances. + </para> + + <note> + <para> + Two keep two databases synchronized with each other, you need + to set replication in both directions; that is, you must + replicate from <literal>databasea</literal> to + <literal>databaseb</literal>, and separately from + <literal>databaseb</literal> to <literal>databasea</literal>. + </para> + </note> + + </section> + + <section id="couchdb-api-misc_replicate_post-cancel"> + + <title>Canceling Continuous Replication</title> + + <para> + You can cancel continuous replication by adding the + <literal>cancel</literal> field to the JSON request object and + setting the value to true. Note that the structure of the + request must be identical to the original for the cancelation + request to be honoured. For example, if you requested continuous + replication, the cancellation request must also contain the + <literal>continuous</literal> field. + </para> + + <para> + For example, the replication request: + </para> + +<programlisting> +POST http://couchdb:5984/_replicate +Content-Type: application/json +Accept: application/json + +{ + "source" : "recipes", + "target" : "http://couchdb-remote:5984/recipes", + "create_target" : true, + "continuous" : true +} +</programlisting> + + <para> + Must be canceled using the request: + </para> + +<programlisting> +POST http://couchdb:5984/_replicate +Content-Type: application/json +Accept: application/json + +{ + "cancel" : true, + "continuous" : true + "create_target" : true, + "source" : "recipes", + "target" : "http://couchdb-remote:5984/recipes", +} +</programlisting> + + <para> + Requesting cancellation of a replication that does not exist + results in a 404 error. + </para> + + </section> + + </section> + + <section id="couchdb-api-misc_restart_post"> + + <title><literal>POST /_restart</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API POST /_restart</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>POST /_restart</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + JSON status message + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">yes</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>201</entry><entry namest="info" nameend="addinfo"> + Document created successfully. + </entry></row></tbody></tgroup></informaltable> + + <para> + Restarts the CouchDB instance. You must be authenticated as a user + with administration privileges for this to work. + </para> + + <para> + For example: + </para> + +<programlisting> +POST http://admin:password@couchdb:5984/_restart +</programlisting> + + <para> + The return value (if the server has not already restarted) is a + JSON status object indicating that the request has been received: + </para> + +<programlisting> +{ + "ok" : true, +} +</programlisting> + + <para> + If the server has already restarted, the header may be returned, + but no actual data is contained in the response. + </para> + + </section> + + <section id="couchdb-api-misc_stats_get"> + + <title><literal>GET /_stats</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /_stats</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /_stats</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Server statistics + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Request completed successfully. + </entry></row></tbody></tgroup></informaltable> + + <para> + The <literal>_stats</literal> method returns a JSON object + containting the statistics for the running server. The object is + structured with top-level sections collating the statistics for a + range of entries, with each individual statistic being easily + identified, and the content of each statistic is self-describing. + For example, the request time statistics, within the + <literal>couchdb</literal> section are structured as follows: + </para> + +<programlisting> +{ + "couchdb" : { +... + "request_time" : { + "stddev" : "27.509", + "min" : "0.333333333333333", + "max" : "152", + "current" : "400.976", + "mean" : "10.837", + "sum" : "400.976", + "description" : "length of a request inside CouchDB without MochiWeb" + }, +... + } +} + </programlisting> + + <para> + The fields provide the current, minimum and maximum, and a + collection of statistical means and quantities. The quantity in + each case is not defined, but the descriptions below provide + </para> + + <para> + The statistics are divided into the following top-level sections: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal>couchdb</literal> + </para> + + <para> + Describes statistics specific to the internals of CouchDB. + </para> + + <table> + <title><literal>couchdb</literal> statistics</title> + <tgroup cols="3"> + <colspec colname="stat"/> + <colspec colname="desc"/> + <colspec colname="unit"/> + <thead> + <row> + <entry> + Statistic ID + </entry> + <entry> + Description + </entry> + <entry> + Unit + </entry> + </row> + </thead> + <tbody> + <row> + <entry><literal>auth_cache_hits</literal> + </entry> + <entry> + Number of authentication cache hits + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>auth_cache_misses</literal> + </entry> + <entry> + Number of authentication cache misses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>database_reads</literal> + </entry> + <entry> + Number of times a document was read from a database + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>database_writes</literal> + </entry> + <entry> + Number of times a database was changed + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>open_databases</literal> + </entry> + <entry> + Number of open databases + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>open_os_files</literal> + </entry> + <entry> + Number of file descriptors CouchDB has open + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>request_time</literal> + </entry> + <entry> + Length of a request inside CouchDB without MochiWeb + </entry> + <entry> + milliseconds + </entry> + </row> + </tbody> + </tgroup> + </table> + </listitem> + + <listitem> + <para> + <literal>httpd_request_methods</literal> + </para> + + <table> + <title><literal>httpd_request_methods</literal> statistics</title> + <tgroup cols="3"> + <colspec colname="stat"/> + <colspec colname="desc"/> + <colspec colname="unit"/> + <thead> + <row> + <entry> + Statistic ID + </entry> + <entry> + Description + </entry> + <entry> + Unit + </entry> + </row> + </thead> + <tbody> + <row> + <entry><literal>COPY</literal> + </entry> + <entry> + Number of HTTP COPY requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>DELETE</literal> + </entry> + <entry> + Number of HTTP DELETE requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>GET</literal> + </entry> + <entry> + Number of HTTP GET requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>HEAD</literal> + </entry> + <entry> + Number of HTTP HEAD requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>POST</literal> + </entry> + <entry> + Number of HTTP POST requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>PUT</literal> + </entry> + <entry> + Number of HTTP PUT requests + </entry> + <entry> + number + </entry> + </row> + </tbody> + </tgroup> + </table> + </listitem> + + <listitem> + <para> + <literal>httpd_status_codes</literal> + </para> + + <table> + <title><literal>httpd_status_codes</literal> statistics</title> + <tgroup cols="3"> + <colspec colname="stat"/> + <colspec colname="desc"/> + <colspec colname="unit"/> + <thead> + <row> + <entry> + Statistic ID + </entry> + <entry> + Description + </entry> + <entry> + Unit + </entry> + </row> + </thead> + <tbody> + <row> + <entry><literal>200</literal> + </entry> + <entry> + Number of HTTP 200 OK responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>201</literal> + </entry> + <entry> + Number of HTTP 201 Created responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>202</literal> + </entry> + <entry> + Number of HTTP 202 Accepted responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>301</literal> + </entry> + <entry> + Number of HTTP 301 Moved Permanently responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>304</literal> + </entry> + <entry> + Number of HTTP 304 Not Modified responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>400</literal> + </entry> + <entry> + Number of HTTP 400 Bad Request responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>401</literal> + </entry> + <entry> + Number of HTTP 401 Unauthorized responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>403</literal> + </entry> + <entry> + Number of HTTP 403 Forbidden responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>404</literal> + </entry> + <entry> + Number of HTTP 404 Not Found responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>405</literal> + </entry> + <entry> + Number of HTTP 405 Method Not Allowed responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>409</literal> + </entry> + <entry> + Number of HTTP 409 Conflict responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>412</literal> + </entry> + <entry> + Number of HTTP 412 Precondition Failed responses + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>500</literal> + </entry> + <entry> + Number of HTTP 500 Internal Server Error responses + </entry> + <entry> + number + </entry> + </row> + </tbody> + </tgroup> + </table> + </listitem> + + <listitem> + <para> + <literal>httpd</literal> + </para> + + <table> + <title><literal>httpd</literal> statistics</title> + <tgroup cols="3"> + <colspec colname="stat"/> + <colspec colname="desc"/> + <colspec colname="unit"/> + <thead> + <row> + <entry> + Statistic ID + </entry> + <entry> + Description + </entry> + <entry> + Unit + </entry> + </row> + </thead> + <tbody> + <row> + <entry><literal>bulk_requests</literal> + </entry> + <entry> + Number of bulk requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>clients_requesting_changes</literal> + </entry> + <entry> + Number of clients for continuous _changes + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>requests</literal> + </entry> + <entry> + Number of HTTP requests + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>temporary_view_reads</literal> + </entry> + <entry> + Number of temporary view reads + </entry> + <entry> + number + </entry> + </row> + <row> + <entry><literal>view_reads</literal> + </entry> + <entry> + Number of view reads + </entry> + <entry> + number + </entry> + </row> + </tbody> + </tgroup> + </table> + </listitem> + + </itemizedlist> + + <para> + You can also access individual statistics by quoting the + statistics sections and statistic ID as part of the URL path. For + example, to get the <literal>request_time</literal> statistics, + you can use: + </para> + +<programlisting> +GET /_stats/couchdb/request_time + </programlisting> + + <para> + This returns an entire statistics object, as with the full + request, but containining only the request individual statistic. + Hence, the returned structure is as follows: + </para> + +<programlisting> +{ + "couchdb" : { + "request_time" : { + "stddev" : 7454.305, + "min" : 1, + "max" : 34185, + "current" : 34697.803, + "mean" : 1652.276, + "sum" : 34697.803, + "description" : "length of a request inside CouchDB without MochiWeb" + } + } +} + </programlisting> + + </section> + + <section id="couchdb-api-misc_utils_get"> + + <title><literal>GET /_utils</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /_utils</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /_utils</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Administration interface + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row></tbody></tgroup></informaltable> + + <para> + Accesses the built-in Futon administration interface for CouchDB. + </para> + + </section> + + <section id="couchdb-api-misc_uuids_get"> + + <title><literal>GET /_uuids</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /_uuids</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /_uuids</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + List of UUIDs + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry><emphasis role="bold">Query Arguments</emphasis></entry><entry><emphasis role="bold">Argument</emphasis></entry><entry><literal>count</literal></entry></row><row><entry></entry><entry><emphasis role="bold">Description</emphasis></entry><entry> + Number of UUIDs to return + </entry></row><row><entry></entry><entry><emphasis role="bold">Optional</emphasis></entry><entry>yes</entry></row><row><entry></entry><entry><emphasis role="bold">Type</emphasis></entry><entry>numeric</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Request completed successfully. + </entry></row></tbody></tgroup></informaltable> + + <para> + Requests one or more Universally Unique Identifiers (UUIDs) from + the CouchDB instance. The response is a JSON object providing a + list of UUIDs. For example: + </para> + +<programlisting> +{ + "uuids" : [ + "7e4b5a14b22ec1cf8e58b9cdd0000da3" + ] +} +</programlisting> + + <para> + You can use the <literal>count</literal> argument to specify the + number of UUIDs to be returned. For example: + </para> + +<programlisting> + GET http://couchdb:5984/_uuids?count=5 +</programlisting> + + <para> + Returns: + </para> + +<programlisting> +{ + "uuids" : [ + "c9df0cdf4442f993fc5570225b405a80", + "c9df0cdf4442f993fc5570225b405bd2", + "c9df0cdf4442f993fc5570225b405e42", + "c9df0cdf4442f993fc5570225b4061a0", + "c9df0cdf4442f993fc5570225b406a20" + ] +} +</programlisting> + + <para> + The UUID type is determined by the UUID type setting in the + CouchDB configuration. See + <xref linkend="couchdb-api-config_config-section-key_put"/>. + </para> + + <para> + For example, changing the UUID type to <literal>random</literal>: + </para> + +<programlisting> +PUT http://couchdb:5984/_config/uuids/algorithm +Content-Type: application/json +Accept: */* + +"random" +</programlisting> + + <para> + When obtaining a list of UUIDs: + </para> + +<programlisting> +{ + "uuids" : [ + "031aad7b469956cf2826fcb2a9260492", + "6ec875e15e6b385120938df18ee8e496", + "cff9e881516483911aa2f0e98949092d", + "b89d37509d39dd712546f9510d4a9271", + "2e0dbf7f6c4ad716f21938a016e4e59f" + ] +} +</programlisting> + + </section> + + <section id="couchdb-api-misc_favicon_get"> + + <title><literal>GET /favicon.ico</literal></title> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/URLAPI/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//urlapi/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/URLAPI.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<informaltable><textobject><phrase>URL API GET /favicon.ico</phrase></textobject><tgroup cols="3"><colspec colname="field"/><colspec colname="info"/><colspec colname="addinfo"/><tbody><row><entry><emphasis role="bold">Method</emphasis></entry><entry namest="info" nameend="addinfo"><literal>GET /favicon.ico</literal></entry></row><row><entry><emphasis role="bold">Request</emphasis></entry><entry namest="info" nameend="addinfo"> + None + </entry></row><row><entry><emphasis role="bold">Response</emphasis></entry><entry namest="info" nameend="addinfo"> + Binary content for the favicon.ico site icon + </entry></row><row><entry><emphasis role="bold">Admin Privileges Required</emphasis></entry><entry namest="info" nameend="addinfo">no</entry></row><row><entry namest="field" nameend="addinfo"><emphasis role="bold">Return Codes</emphasis></entry></row><row><entry>200</entry><entry namest="info" nameend="addinfo"> + Request completed successfully. + </entry></row><row><entry>404</entry><entry namest="info" nameend="addinfo"> + The requested content could not be found. The returned content + will include further information, as a JSON object, if available. + </entry></row></tbody></tgroup></informaltable> + + <para> + Returns the site icon. The return <literal>Content-type</literal> + header is <literal>image/x-icon</literal>, and the content stream + is the image data. + </para> + + </section> + +</chapter> diff --git a/share/docs/couchdb-manual-1.1/metadoc-couchdb-config-options.xml b/share/docs/couchdb-manual-1.1/metadoc-couchdb-config-options.xml new file mode 100644 index 000000000..177ab4181 --- /dev/null +++ b/share/docs/couchdb-manual-1.1/metadoc-couchdb-config-options.xml @@ -0,0 +1,413 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE section PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<section id="couchdb-single-config-options"> + + <title>CouchDB Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="section"/><colspec colname="desc"/><thead><row><entry>Section</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>attachments</literal></entry><entry> + Attachment options + </entry></row><row><entry><literal>couchdb</literal></entry><entry> + CouchDB specific options + </entry></row><row><entry><literal>daemons</literal></entry><entry> + Daemons and background processes + </entry></row><row><entry><literal>httpd_db_handlers</literal></entry><entry> + Database Operation handlers + </entry></row><row><entry><literal>couch_httpd_auth</literal></entry><entry> + HTTPD Authentication options + </entry></row><row><entry><literal>httpd</literal></entry><entry> + HTTPD Server options + </entry></row><row><entry><literal>httpd_design_handlers</literal></entry><entry> + Handlers for design document operations + </entry></row><row><entry><literal>httpd_global_handlers</literal></entry><entry> + Handlers for global operations + </entry></row><row><entry><literal>log</literal></entry><entry> + Logging options + </entry></row><row><entry><literal>query_servers</literal></entry><entry> + Query Server options + </entry></row><row><entry><literal>query_server_config</literal></entry><entry> + Query server options + </entry></row><row><entry><literal>replicator</literal></entry><entry> + Replicator Options + </entry></row><row><entry><literal>ssl</literal></entry><entry> + SSL (Secure Sockets Layer) Options + </entry></row><row><entry><literal>stats</literal></entry><entry> + Statistics options + </entry></row><row><entry><literal>uuids</literal></entry><entry> + UUID generation options + </entry></row></tbody></tgroup></table> + + <section id="couchdb-single-config-options_attachments"> + + <title><literal>attachments</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-attachments-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>compressible_types</literal></entry><entry> + compressible_types + </entry></row><row><entry><literal>compression_level</literal></entry><entry> + compression_level + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_couchdb"> + + <title><literal>couchdb</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-couchdb-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>database_dir</literal></entry><entry> + database_dir + </entry></row><row><entry><literal>delayed_commits</literal></entry><entry> + delayed_commits + </entry></row><row><entry><literal>max_attachment_chunk_size</literal></entry><entry> + max_attachment_chunk_size + </entry></row><row><entry><literal>max_dbs_open</literal></entry><entry> + max_dbs_open + </entry></row><row><entry><literal>max_document_size</literal></entry><entry> + max_document_size + </entry></row><row><entry><literal>os_process_timeout</literal></entry><entry> + os_process_timeout + </entry></row><row><entry><literal>uri_file</literal></entry><entry> + uri_file + </entry></row><row><entry><literal>util_driver_dir</literal></entry><entry> + util_driver_dir + </entry></row><row><entry><literal>view_index_dir</literal></entry><entry> + view_index_dir + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_daemons"> + + <title><literal>daemons</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-daemons-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>httpsd</literal></entry><entry> + Enabled HTTPS service + </entry></row><row><entry><literal>auth_cache</literal></entry><entry> + auth_cache + </entry></row><row><entry><literal>db_update_notifier</literal></entry><entry> + db_update_notifier + </entry></row><row><entry><literal>external_manager</literal></entry><entry> + external_manager + </entry></row><row><entry><literal>httpd</literal></entry><entry> + httpd + </entry></row><row><entry><literal>query_servers</literal></entry><entry> + query_servers + </entry></row><row><entry><literal>stats_aggregator</literal></entry><entry> + stats_aggregator + </entry></row><row><entry><literal>stats_collector</literal></entry><entry> + stats_collector + </entry></row><row><entry><literal>uuids</literal></entry><entry> + uuids + </entry></row><row><entry><literal>view_manager</literal></entry><entry> + view_manager + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_httpd_db_handlers"> + + <title><literal>httpd_db_handlers</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-httpd_db_handlers-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>_changes</literal></entry><entry> + _changes + </entry></row><row><entry><literal>_compact</literal></entry><entry> + _compact + </entry></row><row><entry><literal>_design</literal></entry><entry> + _design + </entry></row><row><entry><literal>_temp_view</literal></entry><entry> + _temp_view + </entry></row><row><entry><literal>_view_cleanup</literal></entry><entry> + _view_cleanup + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_couch_httpd_auth"> + + <title><literal>couch_httpd_auth</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-couch_httpd_auth-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>auth_cache_size</literal></entry><entry> + auth_cache_size + </entry></row><row><entry><literal>authentication_db</literal></entry><entry> + authentication_db + </entry></row><row><entry><literal>authentication_redirect</literal></entry><entry> + authentication_redirect + </entry></row><row><entry><literal>require_valid_user</literal></entry><entry> + require_valid_user + </entry></row><row><entry><literal>timeout</literal></entry><entry> + timeout + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_httpd"> + + <title><literal>httpd</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-httpd-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>nodelay</literal></entry><entry> + Enable TCP_NODELAY + </entry></row><row><entry><literal>allow_jsonp</literal></entry><entry> + allow_jsonp + </entry></row><row><entry><literal>authentication_handlers</literal></entry><entry> + authentication_handlers + </entry></row><row><entry><literal>bind_address</literal></entry><entry> + bind_address + </entry></row><row><entry><literal>default_handler</literal></entry><entry> + default_handler + </entry></row><row><entry><literal>max_connections</literal></entry><entry> + max_connections + </entry></row><row><entry><literal>port</literal></entry><entry> + port + </entry></row><row><entry><literal>secure_rewrites</literal></entry><entry> + secure_rewrites + </entry></row><row><entry><literal>vhost_global_handlers</literal></entry><entry> + vhost_global_handlers + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_httpd_design_handlers"> + + <title><literal>httpd_design_handlers</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-httpd_design_handlers-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>_info</literal></entry><entry> + _info + </entry></row><row><entry><literal>_list</literal></entry><entry> + _list + </entry></row><row><entry><literal>_rewrite</literal></entry><entry> + _rewrite + </entry></row><row><entry><literal>_show</literal></entry><entry> + _show + </entry></row><row><entry><literal>_update</literal></entry><entry> + _update + </entry></row><row><entry><literal>_view</literal></entry><entry> + _view + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_httpd_global_handlers"> + + <title><literal>httpd_global_handlers</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-httpd_global_handlers-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>/</literal></entry><entry> + / + </entry></row><row><entry><literal>_active_tasks</literal></entry><entry> + _active_tasks + </entry></row><row><entry><literal>_all_dbs</literal></entry><entry> + _all_dbs + </entry></row><row><entry><literal>_config</literal></entry><entry> + _config + </entry></row><row><entry><literal>_log</literal></entry><entry> + _log + </entry></row><row><entry><literal>_oauth</literal></entry><entry> + _oauth + </entry></row><row><entry><literal>_replicate</literal></entry><entry> + _replicate + </entry></row><row><entry><literal>_restart</literal></entry><entry> + _restart + </entry></row><row><entry><literal>_session</literal></entry><entry> + _session + </entry></row><row><entry><literal>_stats</literal></entry><entry> + _stats + </entry></row><row><entry><literal>_utils</literal></entry><entry> + _utils + </entry></row><row><entry><literal>_uuids</literal></entry><entry> + _uuids + </entry></row><row><entry><literal>favicon.ico</literal></entry><entry> + favicon.ico + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_log"> + + <title><literal>log</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-log-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>file</literal></entry><entry> + file + </entry></row><row><entry><literal>include_sasl</literal></entry><entry> + include_sasl + </entry></row><row><entry><literal>level</literal></entry><entry> + level + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_query_servers"> + + <title><literal>query_servers</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-query_servers-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>javascript</literal></entry><entry> + javascript + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_query_server_config"> + + <title><literal>query_server_config</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-query_server_config-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>reduce_limit</literal></entry><entry> + reduce_limit + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_replicator"> + + <title><literal>replicator</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-replicator-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>max_http_pipeline_size</literal></entry><entry> + max_http_pipeline_size + </entry></row><row><entry><literal>max_http_sessions</literal></entry><entry> + max_http_sessions + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_stats"> + + <title><literal>stats</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-stats-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>rate</literal></entry><entry> + rate + </entry></row><row><entry><literal>samples</literal></entry><entry> + samples + </entry></row></tbody></tgroup></table> + + </section> + + <section id="couchdb-single-config-options_uuids"> + + <title><literal>uuids</literal> Configuration Options</title> + + <para> + + </para> + + <remark role="dependency-meta" condition="../DocKit/bin/CouchDocs/Config/Parser.pm"/> +<remark role="dependency-meta" condition="../metadocs//config/couchdb.xml"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs/Config.pm"/> +<remark role="dependency-tool" condition="../DocKit/bin/CouchDocs.pm"/> +<table id="table-couchdb-single-config-options-uuids-summary"><title>Configuration Groups</title><tgroup cols="2"><colspec colname="option"/><colspec colname="desc"/><thead><row><entry>Option</entry><entry>Description</entry></row></thead><tbody><row><entry><literal>algorithm</literal></entry><entry> + algorithm + </entry></row></tbody></tgroup></table> + + </section> + +</section> diff --git a/share/docs/couchdb-release-1.1/couchdb-release-1.1-ready.xml b/share/docs/couchdb-release-1.1/couchdb-release-1.1-ready.xml new file mode 100644 index 000000000..208b9787a --- /dev/null +++ b/share/docs/couchdb-release-1.1/couchdb-release-1.1-ready.xml @@ -0,0 +1,1154 @@ +<?xml version="1.0" encoding="utf-8" standalone="no"?> +<article id="couchdb-release-1.1"> + + <title>CouchDB Release 1.1 Feature Guide</title> + + <articleinfo> + + <abstract> + + <para> + This document provides details on the new features introduced in + the CouchDB 1.1 release from the CouchDB 1.0.x release series. + </para> + + <para xml:base="../common/docbuilddate.xml"> + <emphasis>Last document update</emphasis>: 25 Jan 2012 14:44; + <emphasis>Document built</emphasis>: 21 Feb 2012 20:8. +</para> + + </abstract> + + </articleinfo> + + <section id="couchdb-release-1.1-upgrading"> + + <title>Upgrading to CouchDB 1.1</title> + + <para> + You can upgrade your existing CouchDB 1.0.x installation to + CouchDB 1.1 without any specific steps or migration. When you run + CouchDB 1.1 the existing data and index files will be opened and + used as normal. + </para> + + <para> + The first time you run a compaction routine on your database + within CouchDB 1.1, the data structure and indexes will be updated + to the new version of the CouchDB database format that can only be + read by CouchDB 1.1 and later. This step is not reversable. Once + the data files have been updated and migrated to the new version + the data files will no longer work with a CouchDB 1.0.x release. + </para> + + <warning> + <para> + If you want to retain support for openein gthe data files in + CouchDB 1.0.x you must back up your data files before performing + the upgrade and compaction process. + </para> + </warning> + + </section> + + <section id="couchb-release-1.1-replicatordb"> + + <title>Replicator Database</title> + + <para> + A database where you + <literal>PUT</literal>/<literal>POST</literal> documents to + trigger replications and you <literal>DELETE</literal> to cancel + ongoing replications. These documents have exactly the same + content as the JSON objects we used to <literal>POST</literal> to + <literal>_replicate</literal> (fields <literal>source</literal>, + <literal>target</literal>, <literal>create_target</literal>, + <literal>continuous</literal>, <literal>doc_ids</literal>, + <literal>filter</literal>, <literal>query_params</literal>. + </para> + + <para> + Replication documents can have a user defined + <literal>_id</literal>. Design documents (and + <literal>_local</literal> documents) added to the replicator + database are ignored. + </para> + + <para> + The default name of this database is + <literal>_replicator</literal>. The name can be changed in the + <filename>local.ini</filename> configuration, section + <literal>[replicator]</literal>, parameter <literal>db</literal>. + </para> + + <section id="couchdb-release-1.1-replicatordb-basics"> + + <title>Basics</title> + + <para> + Let's say you PUT the following document into _replicator: + </para> + +<programlisting>{ + "_id": "my_rep", + "source": "http://myserver.com:5984/foo", + "target": "bar", + "create_target": true +}</programlisting> + + <para> + In the couch log you'll see 2 entries like these: + </para> + +<programlisting>[Thu, 17 Feb 2011 19:43:59 GMT] [info] [<0.291.0>] Document `my_rep` triggered replication `c0ebe9256695ff083347cbf95f93e280+create_target` +[Thu, 17 Feb 2011 19:44:37 GMT] [info] [<0.124.0>] Replication `c0ebe9256695ff083347cbf95f93e280+create_target` finished (triggered by document `my_rep`)</programlisting> + + <para> + As soon as the replication is triggered, the document will be + updated by CouchDB with 3 new fields: + </para> + +<programlisting>{ + "_id": "my_rep", + "source": "http://myserver.com:5984/foo", + "target": "bar", + "create_target": true, + "_replication_id": "c0ebe9256695ff083347cbf95f93e280", + "_replication_state": "triggered", + "_replication_state_time": 1297974122 +}</programlisting> + + <para> + Special fields set by the replicator start with the prefix + <literal>_replication_</literal>. + </para> + + <itemizedlist> + + <listitem> + <para> + <literal>_replication_id</literal> + </para> + + <para> + The ID internally assigned to the replication. This is also + the ID exposed by <literal>/_active_tasks</literal>. + </para> + </listitem> + + <listitem> + <para> + <literal>_replication_state</literal> + </para> + + <para> + The current state of the replication. + </para> + </listitem> + + <listitem> + <para> + <literal>_replication_state_time</literal> + </para> + + <para> + A Unix timestamp (number of seconds since 1 Jan 1970) that + tells us when the current replication state (marked in + <literal>_replication_state</literal>) was set. + </para> + </listitem> + + </itemizedlist> + + <para> + When the replication finishes, it will update the + <literal>_replication_state</literal> field (and + <literal>_replication_state_time</literal>) with the value + <literal>completed</literal>, so the document will look like: + </para> + +<programlisting>{ + "_id": "my_rep", + "source": "http://myserver.com:5984/foo", + "target": "bar", + "create_target": true, + "_replication_id": "c0ebe9256695ff083347cbf95f93e280", + "_replication_state": "completed", + "_replication_state_time": 1297974122 +}</programlisting> + + <para> + When an error happens during replication, the + <literal>_replication_state</literal> field is set to + <literal>error</literal> (and + <literal>_replication_state</literal> gets updated of course). + </para> + + <para> + When you PUT/POST a document to the + <literal>_replicator</literal> database, CouchDB will attempt to + start the replication up to 10 times (configurable under + <literal>[replicator]</literal>, parameter + <literal>max_replication_retry_count</literal>). If it fails on + the first attempt, it waits 5 seconds before doing a second + attempt. If the second attempt fails, it waits 10 seconds before + doing a third attempt. If the third attempt fails, it waits 20 + seconds before doing a fourth attempt (each attempt doubles the + previous wait period). When an attempt fails, the Couch log will + show you something like: + </para> + +<programlisting>[error] [<0.149.0>] Error starting replication `67c1bb92010e7abe35d7d629635f18b6+create_target` (document `my_rep_2`): {db_not_found,<<"could not open http://myserver:5986/foo/">></programlisting> + + <note> + <para> + The <literal>_replication_state</literal> field is only set to + <literal>error</literal> when all the attempts were + unsuccessful. + </para> + </note> + + <para> + There are only 3 possible values for the + <literal>_replication_state</literal> field: + <literal>triggered</literal>, <literal>completed</literal> and + <literal>error</literal>. Continuous replications never get + their state set to <literal>completed</literal>. + </para> + + </section> + + <section id="couchdb-release-1.1-replicatordb-docsame"> + + <title>Documents describing the same replication</title> + + <para> + Lets suppose 2 documents are added to the + <literal>_replicator</literal> database in the following order: + </para> + +<programlisting>{ + "_id": "doc_A", + "source": "http://myserver.com:5984/foo", + "target": "bar" +}</programlisting> + + <para> + and + </para> + +<programlisting>{ + "_id": "doc_B", + "source": "http://myserver.com:5984/foo", + "target": "bar" +}</programlisting> + + <para> + Both describe exactly the same replication (only their + <literal>_ids</literal> differ). In this case document + <literal>doc_A</literal> triggers the replication, getting + updated by CouchDB with the fields + <literal>_replication_state</literal>, + <literal>_replication_state_time</literal> and + <literal>_replication_id</literal>, just like it was described + before. Document <literal>doc_B</literal> however, is only + updated with one field, the <literal>_replication_id</literal> + so it will look like this: + </para> + +<programlisting>{ + "_id": "doc_B", + "source": "http://myserver.com:5984/foo", + "target": "bar", + "_replication_id": "c0ebe9256695ff083347cbf95f93e280" +}</programlisting> + + <para> + While document <literal>doc_A</literal> will look like this: + </para> + +<programlisting>{ + "_id": "doc_A", + "source": "http://myserver.com:5984/foo", + "target": "bar", + "_replication_id": "c0ebe9256695ff083347cbf95f93e280", + "_replication_state": "triggered", + "_replication_state_time": 1297974122 +}</programlisting> + + <para> + Note that both document get exactly the same value for the + <literal>_replication_id</literal> field. This way you can + identify which documents refer to the same replication - you can + for example define a view which maps replication IDs to document + IDs. + </para> + + </section> + + <section id="couchdb-release-1.1-replicatordb-cancel"> + + <title>Canceling replications</title> + + <para> + To cancel a replication simply <literal>DELETE</literal> the + document which triggered the replication. The Couch log will + show you an entry like the following: + </para> + +<programlisting>[Thu, 17 Feb 2011 20:16:29 GMT] [info] [<0.125.0>] Stopped replication `c0ebe9256695ff083347cbf95f93e280+continuous+create_target` because replication document `doc_A` was deleted</programlisting> + + <note> + <para> + You need to <literal>DELETE</literal> the document that + triggered the replication. <literal>DELETE</literal>ing + another document that describes the same replication but did + not trigger it, will not cancel the replication. + </para> + </note> + + </section> + + <section id="couchdb-release-1.1-replicatordb-restart"> + + <title>Server restart</title> + + <para> + When CouchDB is restarted, it checks its + <literal>_replicator</literal> database and restarts any + replication that is described by a document that either has its + <literal>_replication_state</literal> field set to + <literal>triggered</literal> or it doesn't have yet the + <literal>_replication_state</literal> field set. + </para> + + <note> + <para> + Continuous replications always have a + <literal>_replication_state</literal> field with the value + <literal>triggered</literal>, therefore they're always + restarted when CouchDB is restarted. + </para> + </note> + + </section> + + <section id="couchdb-release-1.1-replicatordb-changing"> + + <title>Changing the Replicator Database</title> + + <para> + Imagine your replicator database (default name is _replicator) + has the two following documents that represent pull replications + from servers A and B: + </para> + +<programlisting>{ + "_id": "rep_from_A", + "source": "http://aserver.com:5984/foo", + "target": "foo_a", + "continuous": true, + "_replication_id": "c0ebe9256695ff083347cbf95f93e280", + "_replication_state": "triggered", + "_replication_state_time": 1297971311 +} +{ + "_id": "rep_from_B", + "source": "http://bserver.com:5984/foo", + "target": "foo_b", + "continuous": true, + "_replication_id": "231bb3cf9d48314eaa8d48a9170570d1", + "_replication_state": "triggered", + "_replication_state_time": 1297974122 +}</programlisting> + + <para> + Now without stopping and restarting CouchDB, you change the name + of the replicator database to + <literal>another_replicator_db</literal>: + </para> + +<programlisting>$ curl -X PUT http://localhost:5984/_config/replicator/db -d '"another_replicator_db"' +"_replicator"</programlisting> + + <para> + As soon as this is done, both pull replications defined before, + are stopped. This is explicitly mentioned in CouchDB's log: + </para> + +<programlisting>[Fri, 11 Mar 2011 07:44:20 GMT] [info] [<0.104.0>] Stopping all ongoing replications because the replicator database was deleted or changed +[Fri, 11 Mar 2011 07:44:20 GMT] [info] [<0.127.0>] 127.0.0.1 - - PUT /_config/replicator/db 200</programlisting> + + <para> + Imagine now you add a replication document to the new replicator + database named <literal>another_replicator_db</literal>: + </para> + +<programlisting>{ + "_id": "rep_from_X", + "source": "http://xserver.com:5984/foo", + "target": "foo_x", + "continuous": true +}</programlisting> + + <para> + From now own you have a single replication going on in your + system: a pull replication pulling from server X. Now you change + back the replicator database to the original one + <literal>_replicator</literal>: + </para> + +<programlisting>$ curl -X PUT http://localhost:5984/_config/replicator/db -d '"_replicator"' +"another_replicator_db"</programlisting> + + <para> + Immediately after this operation, the replication pulling from + server X will be stopped and the replications defined in the + _replicator database (pulling from servers A and B) will be + resumed. + </para> + + <para> + Changing again the replicator database to + <literal>another_replicator_db</literal> will stop the pull + replications pulling from servers A and B, and resume the pull + replication pulling from server X. + </para> + + </section> + + <section id="couchdb-release-1.1-replicatordb-replicating"> + + <title>Replicating the replicator database</title> + + <para> + Imagine you have in server C a replicator database with the two + following pull replication documents in it: + </para> + +<programlisting>{ + "_id": "rep_from_A", + "source": "http://aserver.com:5984/foo", + "target": "foo_a", + "continuous": true, + "_replication_id": "c0ebe9256695ff083347cbf95f93e280", + "_replication_state": "triggered", + "_replication_state_time": 1297971311 +} +{ + "_id": "rep_from_B", + "source": "http://bserver.com:5984/foo", + "target": "foo_b", + "continuous": true, + "_replication_id": "231bb3cf9d48314eaa8d48a9170570d1", + "_replication_state": "triggered", + "_replication_state_time": 1297974122 +}</programlisting> + + <para> + Now you would like to have the same pull replications going on + in server D, that is, you would like to have server D pull + replicating from servers A and B. You have two options: + </para> + + <itemizedlist> + + <listitem> + <para> + Explicitly add two documents to server's D replicator + database + </para> + </listitem> + + <listitem> + <para> + Replicate server's C replicator database into server's D + replicator database + </para> + </listitem> + + </itemizedlist> + + <para> + Both alternatives accomplish exactly the same goal. + </para> + + </section> + + <section id="couchdb-release-1.1-replicatordb-delegations"> + + <title>Delegations</title> + + <para> + Replication documents can have a custom + <literal>user_ctx</literal> property. This property defines the + user context under which a replication runs. For the old way of + triggering replications (POSTing to + <literal>/_replicate/</literal>), this property was not needed + (it didn't exist in fact) - this is because at the moment of + triggering the replication it has information about the + authenticated user. With the replicator database, since it's a + regular database, the information about the authenticated user + is only present at the moment the replication document is + written to the database - the replicator database implementation + is like a _changes feed consumer (with + <literal>?include_docs=true</literal>) that reacts to what was + written to the replicator database - in fact this feature could + be implemented with an external script/program. This + implementation detail implies that for non admin users, a + <literal>user_ctx</literal> property, containing the user's name + and a subset of his/her roles, must be defined in the + replication document. This is ensured by the document update + validation function present in the default design document of + the replicator database. This validation function also ensure + that a non admin user can set a user name property in the + <literal>user_ctx</literal> property that doesn't match his/her + own name (same principle applies for the roles). + </para> + + <para> + For admins, the <literal>user_ctx</literal> property is + optional, and if it's missing it defaults to a user context with + name null and an empty list of roles - this mean design + documents will not be written to local targets. If writing + design documents to local targets is desired, the a user context + with the roles <literal>_admin</literal> must be set explicitly. + </para> + + <para> + Also, for admins the <literal>user_ctx</literal> property can be + used to trigger a replication on behalf of another user. This is + the user context that will be passed to local target database + document validation functions. + </para> + + <note> + <para> + The <literal>user_ctx</literal> property only has effect for + local endpoints. + </para> + </note> + + <para> + Example delegated replication document: + </para> + +<programlisting>{ + "_id": "my_rep", + "source": "http://bserver.com:5984/foo", + "target": "bar", + "continuous": true, + "user_ctx": { + "name": "joe", + "roles": ["erlanger", "researcher"] + } +}</programlisting> + + <para> + As stated before, for admins the user_ctx property is optional, + while for regular (non admin) users it's mandatory. When the + roles property of <literal>user_ctx</literal> is missing, it + defaults to the empty list <literal>[ ]</literal>. + </para> + + </section> + + </section> + + <section id="couchdb-release-1.1-ssl"> + + <title>Native SSL Support</title> + + <para> + CouchDB 1.1 supports SSL natively. All your secure connection + needs can now be served without the need set and maintain a + separate proxy server that handles SSL. + </para> + + <para> + SSL setup can be tricky, but the configuration in CouchDB was + designed to be as easy as possible. All you need is two files; a + certificate and a private key. If you bought an official SSL + certificate from a certificate authority, both should be in your + possession already. + </para> + + <para> + If you just want to try this out and don't want to pay anything + upfront, you can create a self-signed certificate. Everything will + work the same, but clients will get a warning about an insecure + certificate. + </para> + + <para> + You will need the OpenSSL command line tool installed. It probably + already is. + </para> + +<programlisting>shell> <userinput>mkdir cert && cd cert</userinput> +shell> <userinput>openssl genrsa > privkey.pem</userinput> +shell> <userinput>openssl req -new -x509 -key privkey.pem -out mycert.pem -days 1095</userinput> +shell> <userinput>ls</userinput> +mycert.pem privkey.pem</programlisting> + + <para> + Now, you need to edit CouchDB's configuration, either by editing + your <filename>local.ini</filename> file or using the + <literal>/_config</literal> API calls or the configuration screen + in Futon. Here is what you need to do in + <filename>local.ini</filename>, you can infer what needs doing in + the other places. + </para> + + <para> + Be sure to make these edits. Under <literal>[daemons]</literal> + you should see: + </para> + +<programlisting>; enable SSL support by uncommenting the following line and supply the PEM's below. +; the default ssl port CouchDB listens on is 6984 +;httpsd = {couch_httpd, start_link, [https]}</programlisting> + + <para> + Here uncomment the last line: + </para> + +<programlisting>httpsd = {couch_httpd, start_link, [https]}</programlisting> + + <para> + Next, under <literal>[ssl]</literal> you will see: + </para> + +<programlisting>;cert_file = /full/path/to/server_cert.pem +;key_file = /full/path/to/server_key.pem</programlisting> + + <para> + Uncomment and adjust the paths so it matches your system's paths: + </para> + +<programlisting>cert_file = /home/jan/cert/mycert.pem +key_file = /home/jan/cert/privkey.pem</programlisting> + + <para> + For more information please read + <ulink url="http://www.openssl.org/docs/HOWTO/certificates.txt">http://www.openssl.org/docs/HOWTO/certificates.txt</ulink>. + </para> + + <para> + Now start (or restart) CouchDB. You should be able to connect to + it using HTTPS on port 6984: + </para> + +<programlisting>shell> <userinput>curl https://127.0.0.1:6984/</userinput> +curl: (60) SSL certificate problem, verify that the CA cert is OK. Details: +error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed +More details here: http://curl.haxx.se/docs/sslcerts.html + +curl performs SSL certificate verification by default, using a "bundle" +of Certificate Authority (CA) public keys (CA certs). If the default +bundle file isn't adequate, you can specify an alternate file +using the --cacert option. +If this HTTPS server uses a certificate signed by a CA represented in +the bundle, the certificate verification probably failed due to a +problem with the certificate (it might be expired, or the name might +not match the domain name in the URL). +If you'd like to turn off curl's verification of the certificate, use +the -k (or --insecure) option.</programlisting> + + <para> + Oh no what happened?! — Remember, clients will notify their + users that your certificate is self signed. + <command>curl</command> is the client in this case and it notifies + you. Luckily you trust yourself (don't you?) and you can specify + the <option>-k</option> option as the message reads: + </para> + +<programlisting>shell> <userinput>curl -k https://127.0.0.1:6984/</userinput> +{"couchdb":"Welcome","version":"1.1.0"}</programlisting> + + <para> + All done. + </para> + + </section> + + <section id="couchdb-release-1.1-httprange"> + + <title>HTTP Range Requests</title> + + <para> + HTTP allows you to specify byte ranges for requests. This allows + the implementation of resumable downloads and skippable audio and + video streams alike. Now this is available for all attachments + inside CouchDB. + </para> + + <para> + This is just a real quick run through how this looks under the + hood. Usually, you will have larger binary files to serve from + CouchDB, like MP3s and videos, but to make things a little more + obvious, I use a text file here (Note that I use the + <literal>application/octet-stream</literal> Content-Type instead + of <literal>text/plain</literal>). + </para> + +<programlisting>shell> <userinput>cat file.txt </userinput> +My hovercraft is full of eels!</programlisting> + + <para> + Now lets store this text file as an attachment in CouchDB. First, + we create a database: + </para> + +<programlisting>shell> <userinput>curl -X PUT http://127.0.0.1:5984/test</userinput> +{"ok":true}</programlisting> + + <para> + Then we create a new document and the file attachment in one go: + </para> + +<programlisting>shell> <userinput>curl -X PUT http://127.0.0.1:5984/test/doc/file.txt -H "Content-Type: application/octet-stream" -d@file.txt</userinput> +{"ok":true,"id":"doc","rev":"1-287a28fa680ae0c7fb4729bf0c6e0cf2"}</programlisting> + + <para> + Now we can request the whole file easily: + </para> + +<programlisting>shell> <userinput>curl -X GET http://127.0.0.1:5984/test/doc/file.txt</userinput> +My hovercraft is full of eels!</programlisting> + + <para> + But say we only want the first 13 bytes: + </para> + +<programlisting>shell> <userinput>curl -X GET http://127.0.0.1:5984/test/doc/file.txt -H "Range: bytes=0-12"</userinput> +My hovercraft</programlisting> + + <para> + HTTP supports many ways to specify single and even multiple byte + rangers. Read all about it in + <ulink url="http://tools.ietf.org/html/rfc2616#section-14.27">RFC + 2616</ulink>. + </para> + + <note> + <para> + Databases that have been created with CouchDB 1.0.2 or earlier + will support range requests in 1.1.0, but they are using a + less-optimal algorithm. If you plan to make heavy use of this + feature, make sure to compact your database with CouchDB 1.1.0 + to take advantage of a better algorithm to find byte ranges. + </para> + </note> + + </section> + + <section id="couchdb-release-1.1-proxying"> + + <title>HTTP Proxying</title> + + <para> + The HTTP proxy feature makes it easy to map and redirect different + content through your CouchDB URL. The proxy works by mapping a + pathname and passing all content after that prefix through to the + configured proxy address. + </para> + + <para> + Configuration of the proxy redirect is handled through the + <literal>[httpd_global_handlers]</literal> section of the CouchDB + configuration file (typically <filename>local.ini</filename>). The + format is: + </para> + +<programlisting>[httpd_global_handlers] +PREFIX = {couch_httpd_proxy, handle_proxy_req, <<"DESTINATION">>}</programlisting> + + <para> + Where: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal>PREFIX</literal> + </para> + + <para> + Is the string that will be matched. The string can be any + valid qualifier, although to ensure that existing database + names are not overridden by a proxy configuration, you can use + an underscore prefix. + </para> + </listitem> + + <listitem> + <para> + <literal>DESTINATION</literal> + </para> + + <para> + The fully-qualified URL to which the request should be sent. + The destination must include the <literal>http</literal> + prefix. The content is used verbatim in the original request, + so you can also forward to servers on different ports and to + specific paths on the target host. + </para> + </listitem> + + </itemizedlist> + + <para> + The proxy process then translates requests of the form: + </para> + +<programlisting>http://couchdb:5984/PREFIX/path</programlisting> + + <para> + To: + </para> + +<programlisting>DESTINATION/path</programlisting> + + <note> + <para> + Everything after <literal>PREFIX</literal> including the + required forward slash will be appended to the + <literal>DESTINATION</literal>. + </para> + </note> + + <para> + The response is then communicated back to the original client. + </para> + + <para> + For example, the following configuration: + </para> + +<programlisting>_google = {couch_httpd_proxy, handle_proxy_req, <<"http://www.google.com">>}</programlisting> + + <para> + Would forward all requests for + <literal>http://couchdb:5984/_google</literal> to the Google + website. + </para> + + <para> + The service can also be used to forward to related CouchDB + services, such as Lucene: + </para> + +<programlisting>[httpd_global_handlers] +_fti = {couch_httpd_proxy, handle_proxy_req, <<"http://127.0.0.1:5985">>}</programlisting> + + <note> + <para> + The proxy service is basic. If the request is not identified by + the <literal>DESTINATION</literal>, or the remainder of the + <literal>PATH</literal> specification is incomplete, the + original request URL is interpreted as if the + <literal>PREFIX</literal> component of that URL does not exist. + </para> + + <para> + For example, requesting + <literal>http://couchdb:5984/_intranet/media</literal> when + <filename>/media</filename> on the proxy destination does not + exist, will cause the request URL to be interpreted as + <literal>http://couchdb:5984/media</literal>. Care should be + taken to ensure that both requested URLs and destination URLs + are able to cope + </para> + </note> + + </section> + + <section id="couchdb-release-1.1-commonjs"> + + <title>Added CommonJS support to map functions</title> + + <para> + We didn't have CommonJS require in map functions because the + current CommonJS implementation is scoped to the whole design doc, + and giving views access to load code from anywhere in the design + doc would mean we'd have to blow away your view index any time you + changed anything. Having to rebuild views from scratch just + because you changed some CSS or a show function isn't fun, so we + avoided the issue by keeping CommonJS require out of map and + reduce altogether. + </para> + + <para> + The solution we came up with is to allow CommonJS inside map and + reduce funs, but only of libraries that are stored inside the + views part of the design doc. + </para> + + <para> + So you could continue to access CommonJS code in design_doc.foo, + from your list functions etc, but we'd add the ability to require + CommonJS modules within map and reduce, but only from + design_doc.views.lib + </para> + + <para> + There's no worry here about namespace collisions, as Couch just + plucks <literal>views.*.map</literal> and + <literal>views.*.reduce</literal> out of the design doc. So you + could have a view called <literal>lib</literal> if you wanted, and + still have CommonJS stored in <literal>views.lib.sha1</literal> + and <literal>views.lib.stemmer</literal> if you wanted. + </para> + + <para> + We simplified the implementation by enforcing that CommonJS + modules to be used in map functions be stored in views.lib. + </para> + + <para> + A sample design doc (taken from the test suite in Futon) is below: + </para> + +<programlisting>{ + "views" : { + "lib" : { + "baz" : "exports.baz = 'bam';", + "foo" : { + "zoom" : "exports.zoom = 'yeah';", + "boom" : "exports.boom = 'ok';", + "foo" : "exports.foo = 'bar';" + } + }, + "commonjs" : { + "map" : "function(doc) { emit(null, require('views/lib/foo/boom').boom)}" + } + }, + "_id" : "_design/test" +}</programlisting> + + <para> + The <literal>require()</literal> statement is relative to the + design document, but anything loaded form outside of + <literal>views/lib</literal> will fail. + </para> + + </section> + + <section id="couchdb-release-1.1-etag"> + + <title>More granular ETag support for views</title> + + <para> + ETags have been assigned to a map/reduce group (the collection of + views in a single design document). Any change to any of the + indexes for those views would generate a new ETag for all view + URL's in a single design doc, even if that specific view's results + had not changed. + </para> + + <para> + In CouchDB 1.1 each <literal>_view</literal> URL has it's own ETag + which only gets updated when changes are made to the database that + effect that index. If the index for that specific view does not + change, that view keeps the original ETag head (therefore sending + back 304 Not Modified more often). + </para> + + </section> + + <section id="couchdb-release-1.1-filters"> + + <title>Added built-in filters for <literal>_changes</literal>: + <literal>_doc_ids</literal> and <literal>_design</literal>.</title> + + <para> + The <literal>_changes</literal> feed can now be used to watch + changes to specific document ID's or the list of + <literal>_design</literal> documents in a database. If the + <literal>filters</literal> parameter is set to + <literal>_doc_ids</literal> a list of doc IDs can be passed in the + "doc_ids" as a JSON array. + </para> + + </section> + + <section id="couchdb-release-1.1-wildcards"> + + <title>Allow wildcards in vhosts definitions</title> + + <para> + Similar to the rewrites section of a <literal>_design</literal> + document, the new <literal>vhosts</literal> system uses variables + in the form of :varname or wildcards in the form of asterisks. The + variable results can be output into the resulting path as they are + in the rewriter. + </para> + + </section> + + <section id="couchdb-release-1.1-osprocess"> + + <title>OS Daemons</title> + + <para> + CouchDB now supports starting external processes. The support is + simple and enables CouchDB to start each configured OS daemon. If + the daemon stops at any point, CouchDB will restart it (with + protection to ensure regularly failing daemons are not repeatedly + restarted). + </para> + + <para> + The daemon starting process is one-to-one; for each each + configured daemon in the configuration file, CouchDB will start + exactly one instance. If you need to run multiple instances, then + you must create separate individual configurations. Daemons are + configured within the <literal>[os_daemons]</literal> section of + your configuration file (<filename>local.ini</filename>). The + format of each configured daemon is: + </para> + +<programlisting>NAME = PATH ARGS</programlisting> + + <para> + Where <literal>NAME</literal> is an arbitrary (and unique) name to + identify the daemon; <literal>PATH</literal> is the full path to + the daemon to be executed; <literal>ARGS</literal> are any + required arguments to the daemon. + </para> + + <para> + For example: + </para> + +<programlisting>[os_daemons] +basic_responder = /usr/local/bin/responsder.js</programlisting> + + <para> + There is no interactivity between CouchDB and the running process, + but you can use the OS Daemons service to create new HTTP servers + and responders and then use the new proxy service to redirect + requests and output to the CouchDB managed service. For more + information on proxying, see + <xref linkend="couchdb-release-1.1-proxying"/>. For further + background on the OS Daemon service, see + <ulink url="http://davispj.com/2010/09/26/new-couchdb-externals-api.html">CouchDB + Externals API</ulink> + </para> + + </section> + + <section id="coudhdb-release-1.1-updateafter"> + + <title>Stale views and <literal>update_after</literal></title> + + <para> + Currently a view request can include the + <literal>stale=ok</literal> query argument, which allows the + contents of a stale view index to be used to produce the view + output. In order to trigger a build of the outdated view index, a + second view request must be made. + </para> + + <para> + To simplify this process, the <literal>update_after</literal> + value can be supplied to the <literal>stale</literal> query + argument. This triggers a rebuild of the view index after the + results of the view have been retrieved. + </para> + + </section> + + <section id="couchdb-release-1.1-socketoptions"> + + <title>Socket Options Configuration Setting</title> + + <para> + The socket options for the listening socket in CouchDB can now be + set within the CouchDB configuration file. The setting should be + added to the <literal>[httpd]</literal> section of the file using + the option name <literal>socket_options</literal>. The + specification is as a list of tuples. For example: + </para> + +<programlisting>[httpd] +socket_options = [{recbuf, 262144}, {sndbuf, 262144}, {nodelay, true}]</programlisting> + + <para> + The options supported are a subset of full options supported by + the TCP/IP stack. A list of the supported options are provided in + the + <ulink url="http://www.erlang.org/doc/man/inet.html#setopts-2">Erlang + inet</ulink> documentation. + </para> + + </section> + + <section id="couchdb-release-1.1-serveroptions"> + + <title>Server Options Configuration Setting</title> + + <para> + Server options for the MochiWeb component of CouchDB can now be + added to the configuration file. Settings should be added to the + <literal>server_options</literal> option of the + <literal>[httpd]</literal> section of + <filename>local.ini</filename>. For example: + </para> + +<programlisting>[httpd] +server_options = [{backlog, 128}, {acceptor_pool_size, 16}]</programlisting> + + </section> + + <section id="couchdb-release-1.1-errormessages"> + + <title>Improved Error Messages</title> + + <para> + The errors reported when CouchDB is unable to read a required file + have been updated so that explicit information about the files and + problem can now be identified from the error message. The errors + report file permission access either when reading or writing to + configuration and database files. + </para> + + <para> + The error is raised both through the log file and the error + message returned through the API call as a JSON error message. For + example, when setting configuration values: + </para> + +<programlisting>shell> <userinput>curl -H 'X-Couch-Persist: true' -X PUT http://couchdb:5984/_config/couchdb/delayed_commits -d '"false"'</userinput> +{"error":"file_permission_error","reason":"/etc/couchdb/local.ini"}</programlisting> + + <para> + Errors will always be reported using the + <literal>file_permission_error</literal> error type. + </para> + + <para> + During startup permissions errors on key files are also reported + in the log with a descriptive error message and file location so + that permissions can be fixed before restart. + </para> + + </section> + + <section id="couchdb-release-1.1-microoptimizations"> + + <title>Multiple micro-optimizations when reading data.</title> + + <para> + We found a number of places where CouchDB wouldn't do the absolute + optimal thing when reading data and got rid of quite a few + inefficiencies. The problem with small optimizations all over the + place is that you may not notice them with every use-case, but we + sure hope you can see an improvement overall. + </para> + + </section> + +</article> diff --git a/share/docs/couchdb-release-1.1/couchdb-release-1.1.xml b/share/docs/couchdb-release-1.1/couchdb-release-1.1.xml new file mode 100644 index 000000000..e70142adc --- /dev/null +++ b/share/docs/couchdb-release-1.1/couchdb-release-1.1.xml @@ -0,0 +1,1243 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE article PUBLIC '-//OASIS//DTD DocBook XML V4.5//EN' + 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd' [ +<!ENTITY % every.entities SYSTEM "entities.ent"> +%every.entities; +]> +<article id="couchdb-release-1.1"> + + <title>CouchDB Release 1.1 Feature Guide</title> + + <articleinfo> + + <abstract> + + <para> + This document provides details on the new features introduced in + the CouchDB 1.1 release from the CouchDB 1.0.x release series. + </para> + + <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="../common/docbuilddate.xml"/> + + </abstract> + + </articleinfo> + + <section id="couchdb-release-1.1-upgrading"> + + <title>Upgrading to CouchDB 1.1</title> + + <para> + You can upgrade your existing CouchDB 1.0.x installation to + CouchDB 1.1 without any specific steps or migration. When you run + CouchDB 1.1 the existing data and index files will be opened and + used as normal. + </para> + + <para> + The first time you run a compaction routine on your database + within CouchDB 1.1, the data structure and indexes will be updated + to the new version of the CouchDB database format that can only be + read by CouchDB 1.1 and later. This step is not reversable. Once + the data files have been updated and migrated to the new version + the data files will no longer work with a CouchDB 1.0.x release. + </para> + + <warning> + <para> + If you want to retain support for openein gthe data files in + CouchDB 1.0.x you must back up your data files before performing + the upgrade and compaction process. + </para> + </warning> + + </section> + + <section id="couchb-release-1.1-replicatordb"> + + <title>Replicator Database</title> + + <para> + A database where you + <literal>PUT</literal>/<literal>POST</literal> documents to + trigger replications and you <literal>DELETE</literal> to cancel + ongoing replications. These documents have exactly the same + content as the JSON objects we used to <literal>POST</literal> to + <literal>_replicate</literal> (fields <literal>source</literal>, + <literal>target</literal>, <literal>create_target</literal>, + <literal>continuous</literal>, <literal>doc_ids</literal>, + <literal>filter</literal>, <literal>query_params</literal>. + </para> + + <para> + Replication documents can have a user defined + <literal>_id</literal>. Design documents (and + <literal>_local</literal> documents) added to the replicator + database are ignored. + </para> + + <para> + The default name of this database is + <literal>_replicator</literal>. The name can be changed in the + <filename>local.ini</filename> configuration, section + <literal>[replicator]</literal>, parameter <literal>db</literal>. + </para> + + <section id="couchdb-release-1.1-replicatordb-basics"> + + <title>Basics</title> + + <para> + Let's say you PUT the following document into _replicator: + </para> + +<programlisting> +{ + "_id": "my_rep", + "source": "http://myserver.com:5984/foo", + "target": "bar", + "create_target": true +} +</programlisting> + + <para> + In the couch log you'll see 2 entries like these: + </para> + +<programlisting> +[Thu, 17 Feb 2011 19:43:59 GMT] [info] [<0.291.0>] Document `my_rep` triggered replication `c0ebe9256695ff083347cbf95f93e280+create_target` +[Thu, 17 Feb 2011 19:44:37 GMT] [info] [<0.124.0>] Replication `c0ebe9256695ff083347cbf95f93e280+create_target` finished (triggered by document `my_rep`) +</programlisting> + + <para> + As soon as the replication is triggered, the document will be + updated by CouchDB with 3 new fields: + </para> + +<programlisting> +{ + "_id": "my_rep", + "source": "http://myserver.com:5984/foo", + "target": "bar", + "create_target": true, + "_replication_id": "c0ebe9256695ff083347cbf95f93e280", + "_replication_state": "triggered", + "_replication_state_time": 1297974122 +} +</programlisting> + + <para> + Special fields set by the replicator start with the prefix + <literal>_replication_</literal>. + </para> + + <itemizedlist> + + <listitem> + <para> + <literal>_replication_id</literal> + </para> + + <para> + The ID internally assigned to the replication. This is also + the ID exposed by <literal>/_active_tasks</literal>. + </para> + </listitem> + + <listitem> + <para> + <literal>_replication_state</literal> + </para> + + <para> + The current state of the replication. + </para> + </listitem> + + <listitem> + <para> + <literal>_replication_state_time</literal> + </para> + + <para> + A Unix timestamp (number of seconds since 1 Jan 1970) that + tells us when the current replication state (marked in + <literal>_replication_state</literal>) was set. + </para> + </listitem> + + </itemizedlist> + + <para> + When the replication finishes, it will update the + <literal>_replication_state</literal> field (and + <literal>_replication_state_time</literal>) with the value + <literal>completed</literal>, so the document will look like: + </para> + +<programlisting> +{ + "_id": "my_rep", + "source": "http://myserver.com:5984/foo", + "target": "bar", + "create_target": true, + "_replication_id": "c0ebe9256695ff083347cbf95f93e280", + "_replication_state": "completed", + "_replication_state_time": 1297974122 +} +</programlisting> + + <para> + When an error happens during replication, the + <literal>_replication_state</literal> field is set to + <literal>error</literal> (and + <literal>_replication_state</literal> gets updated of course). + </para> + + <para> + When you PUT/POST a document to the + <literal>_replicator</literal> database, CouchDB will attempt to + start the replication up to 10 times (configurable under + <literal>[replicator]</literal>, parameter + <literal>max_replication_retry_count</literal>). If it fails on + the first attempt, it waits 5 seconds before doing a second + attempt. If the second attempt fails, it waits 10 seconds before + doing a third attempt. If the third attempt fails, it waits 20 + seconds before doing a fourth attempt (each attempt doubles the + previous wait period). When an attempt fails, the Couch log will + show you something like: + </para> + +<programlisting> +[error] [<0.149.0>] Error starting replication `67c1bb92010e7abe35d7d629635f18b6+create_target` (document `my_rep_2`): {db_not_found,<<"could not open http://myserver:5986/foo/">> +</programlisting> + + <note> + <para> + The <literal>_replication_state</literal> field is only set to + <literal>error</literal> when all the attempts were + unsuccessful. + </para> + </note> + + <para> + There are only 3 possible values for the + <literal>_replication_state</literal> field: + <literal>triggered</literal>, <literal>completed</literal> and + <literal>error</literal>. Continuous replications never get + their state set to <literal>completed</literal>. + </para> + + </section> + + <section id="couchdb-release-1.1-replicatordb-docsame"> + + <title>Documents describing the same replication</title> + + <para> + Lets suppose 2 documents are added to the + <literal>_replicator</literal> database in the following order: + </para> + +<programlisting> +{ + "_id": "doc_A", + "source": "http://myserver.com:5984/foo", + "target": "bar" +} +</programlisting> + + <para> + and + </para> + +<programlisting> +{ + "_id": "doc_B", + "source": "http://myserver.com:5984/foo", + "target": "bar" +} +</programlisting> + + <para> + Both describe exactly the same replication (only their + <literal>_ids</literal> differ). In this case document + <literal>doc_A</literal> triggers the replication, getting + updated by CouchDB with the fields + <literal>_replication_state</literal>, + <literal>_replication_state_time</literal> and + <literal>_replication_id</literal>, just like it was described + before. Document <literal>doc_B</literal> however, is only + updated with one field, the <literal>_replication_id</literal> + so it will look like this: + </para> + +<programlisting> +{ + "_id": "doc_B", + "source": "http://myserver.com:5984/foo", + "target": "bar", + "_replication_id": "c0ebe9256695ff083347cbf95f93e280" +} +</programlisting> + + <para> + While document <literal>doc_A</literal> will look like this: + </para> + +<programlisting> +{ + "_id": "doc_A", + "source": "http://myserver.com:5984/foo", + "target": "bar", + "_replication_id": "c0ebe9256695ff083347cbf95f93e280", + "_replication_state": "triggered", + "_replication_state_time": 1297974122 +} +</programlisting> + + <para> + Note that both document get exactly the same value for the + <literal>_replication_id</literal> field. This way you can + identify which documents refer to the same replication - you can + for example define a view which maps replication IDs to document + IDs. + </para> + + </section> + + <section id="couchdb-release-1.1-replicatordb-cancel"> + + <title>Canceling replications</title> + + <para> + To cancel a replication simply <literal>DELETE</literal> the + document which triggered the replication. The Couch log will + show you an entry like the following: + </para> + +<programlisting> +[Thu, 17 Feb 2011 20:16:29 GMT] [info] [<0.125.0>] Stopped replication `c0ebe9256695ff083347cbf95f93e280+continuous+create_target` because replication document `doc_A` was deleted +</programlisting> + + <note> + <para> + You need to <literal>DELETE</literal> the document that + triggered the replication. <literal>DELETE</literal>ing + another document that describes the same replication but did + not trigger it, will not cancel the replication. + </para> + </note> + + </section> + + <section id="couchdb-release-1.1-replicatordb-restart"> + + <title>Server restart</title> + + <para> + When CouchDB is restarted, it checks its + <literal>_replicator</literal> database and restarts any + replication that is described by a document that either has its + <literal>_replication_state</literal> field set to + <literal>triggered</literal> or it doesn't have yet the + <literal>_replication_state</literal> field set. + </para> + + <note> + <para> + Continuous replications always have a + <literal>_replication_state</literal> field with the value + <literal>triggered</literal>, therefore they're always + restarted when CouchDB is restarted. + </para> + </note> + + </section> + + <section id="couchdb-release-1.1-replicatordb-changing"> + + <title>Changing the Replicator Database</title> + + <para> + Imagine your replicator database (default name is _replicator) + has the two following documents that represent pull replications + from servers A and B: + </para> + +<programlisting> +{ + "_id": "rep_from_A", + "source": "http://aserver.com:5984/foo", + "target": "foo_a", + "continuous": true, + "_replication_id": "c0ebe9256695ff083347cbf95f93e280", + "_replication_state": "triggered", + "_replication_state_time": 1297971311 +} +{ + "_id": "rep_from_B", + "source": "http://bserver.com:5984/foo", + "target": "foo_b", + "continuous": true, + "_replication_id": "231bb3cf9d48314eaa8d48a9170570d1", + "_replication_state": "triggered", + "_replication_state_time": 1297974122 +} +</programlisting> + + <para> + Now without stopping and restarting CouchDB, you change the name + of the replicator database to + <literal>another_replicator_db</literal>: + </para> + +<programlisting> +$ curl -X PUT http://localhost:5984/_config/replicator/db -d '"another_replicator_db"' +"_replicator" +</programlisting> + + <para> + As soon as this is done, both pull replications defined before, + are stopped. This is explicitly mentioned in CouchDB's log: + </para> + +<programlisting><![CDATA[ +[Fri, 11 Mar 2011 07:44:20 GMT] [info] [<0.104.0>] Stopping all ongoing replications because the replicator database was deleted or changed +[Fri, 11 Mar 2011 07:44:20 GMT] [info] [<0.127.0>] 127.0.0.1 - - PUT /_config/replicator/db 200 +]]> +</programlisting> + + <para> + Imagine now you add a replication document to the new replicator + database named <literal>another_replicator_db</literal>: + </para> + +<programlisting> +{ + "_id": "rep_from_X", + "source": "http://xserver.com:5984/foo", + "target": "foo_x", + "continuous": true +} +</programlisting> + + <para> + From now own you have a single replication going on in your + system: a pull replication pulling from server X. Now you change + back the replicator database to the original one + <literal>_replicator</literal>: + </para> + +<programlisting> +$ curl -X PUT http://localhost:5984/_config/replicator/db -d '"_replicator"' +"another_replicator_db" +</programlisting> + + <para> + Immediately after this operation, the replication pulling from + server X will be stopped and the replications defined in the + _replicator database (pulling from servers A and B) will be + resumed. + </para> + + <para> + Changing again the replicator database to + <literal>another_replicator_db</literal> will stop the pull + replications pulling from servers A and B, and resume the pull + replication pulling from server X. + </para> + + </section> + + <section id="couchdb-release-1.1-replicatordb-replicating"> + + <title>Replicating the replicator database</title> + + <para> + Imagine you have in server C a replicator database with the two + following pull replication documents in it: + </para> + +<programlisting> +{ + "_id": "rep_from_A", + "source": "http://aserver.com:5984/foo", + "target": "foo_a", + "continuous": true, + "_replication_id": "c0ebe9256695ff083347cbf95f93e280", + "_replication_state": "triggered", + "_replication_state_time": 1297971311 +} +{ + "_id": "rep_from_B", + "source": "http://bserver.com:5984/foo", + "target": "foo_b", + "continuous": true, + "_replication_id": "231bb3cf9d48314eaa8d48a9170570d1", + "_replication_state": "triggered", + "_replication_state_time": 1297974122 +} +</programlisting> + + <para> + Now you would like to have the same pull replications going on + in server D, that is, you would like to have server D pull + replicating from servers A and B. You have two options: + </para> + + <itemizedlist> + + <listitem> + <para> + Explicitly add two documents to server's D replicator + database + </para> + </listitem> + + <listitem> + <para> + Replicate server's C replicator database into server's D + replicator database + </para> + </listitem> + + </itemizedlist> + + <para> + Both alternatives accomplish exactly the same goal. + </para> + + </section> + + <section id="couchdb-release-1.1-replicatordb-delegations"> + + <title>Delegations</title> + + <para> + Replication documents can have a custom + <literal>user_ctx</literal> property. This property defines the + user context under which a replication runs. For the old way of + triggering replications (POSTing to + <literal>/_replicate/</literal>), this property was not needed + (it didn't exist in fact) - this is because at the moment of + triggering the replication it has information about the + authenticated user. With the replicator database, since it's a + regular database, the information about the authenticated user + is only present at the moment the replication document is + written to the database - the replicator database implementation + is like a _changes feed consumer (with + <literal>?include_docs=true</literal>) that reacts to what was + written to the replicator database - in fact this feature could + be implemented with an external script/program. This + implementation detail implies that for non admin users, a + <literal>user_ctx</literal> property, containing the user's name + and a subset of his/her roles, must be defined in the + replication document. This is ensured by the document update + validation function present in the default design document of + the replicator database. This validation function also ensure + that a non admin user can set a user name property in the + <literal>user_ctx</literal> property that doesn't match his/her + own name (same principle applies for the roles). + </para> + + <para> + For admins, the <literal>user_ctx</literal> property is + optional, and if it's missing it defaults to a user context with + name null and an empty list of roles - this mean design + documents will not be written to local targets. If writing + design documents to local targets is desired, the a user context + with the roles <literal>_admin</literal> must be set explicitly. + </para> + + <para> + Also, for admins the <literal>user_ctx</literal> property can be + used to trigger a replication on behalf of another user. This is + the user context that will be passed to local target database + document validation functions. + </para> + + <note> + <para> + The <literal>user_ctx</literal> property only has effect for + local endpoints. + </para> + </note> + + <para> + Example delegated replication document: + </para> + +<programlisting> +{ + "_id": "my_rep", + "source": "http://bserver.com:5984/foo", + "target": "bar", + "continuous": true, + "user_ctx": { + "name": "joe", + "roles": ["erlanger", "researcher"] + } +} +</programlisting> + + <para> + As stated before, for admins the user_ctx property is optional, + while for regular (non admin) users it's mandatory. When the + roles property of <literal>user_ctx</literal> is missing, it + defaults to the empty list <literal>[ ]</literal>. + </para> + + </section> + + </section> + + <section id="couchdb-release-1.1-ssl"> + + <title>Native SSL Support</title> + + <para> + CouchDB 1.1 supports SSL natively. All your secure connection + needs can now be served without the need set and maintain a + separate proxy server that handles SSL. + </para> + + <para> + SSL setup can be tricky, but the configuration in CouchDB was + designed to be as easy as possible. All you need is two files; a + certificate and a private key. If you bought an official SSL + certificate from a certificate authority, both should be in your + possession already. + </para> + + <para> + If you just want to try this out and don't want to pay anything + upfront, you can create a self-signed certificate. Everything will + work the same, but clients will get a warning about an insecure + certificate. + </para> + + <para> + You will need the OpenSSL command line tool installed. It probably + already is. + </para> + +<programlisting> +shell> <userinput>mkdir cert && cd cert</userinput> +shell> <userinput>openssl genrsa > privkey.pem</userinput> +shell> <userinput>openssl req -new -x509 -key privkey.pem -out mycert.pem -days 1095</userinput> +shell> <userinput>ls</userinput> +mycert.pem privkey.pem +</programlisting> + + <para> + Now, you need to edit CouchDB's configuration, either by editing + your <filename>local.ini</filename> file or using the + <literal>/_config</literal> API calls or the configuration screen + in Futon. Here is what you need to do in + <filename>local.ini</filename>, you can infer what needs doing in + the other places. + </para> + + <para> + Be sure to make these edits. Under <literal>[daemons]</literal> + you should see: + </para> + +<programlisting> +; enable SSL support by uncommenting the following line and supply the PEM's below. +; the default ssl port CouchDB listens on is 6984 +;httpsd = {couch_httpd, start_link, [https]} +</programlisting> + + <para> + Here uncomment the last line: + </para> + +<programlisting> +httpsd = {couch_httpd, start_link, [https]} +</programlisting> + + <para> + Next, under <literal>[ssl]</literal> you will see: + </para> + +<programlisting> +;cert_file = /full/path/to/server_cert.pem +;key_file = /full/path/to/server_key.pem +</programlisting> + + <para> + Uncomment and adjust the paths so it matches your system's paths: + </para> + +<programlisting> +cert_file = /home/jan/cert/mycert.pem +key_file = /home/jan/cert/privkey.pem +</programlisting> + + <para> + For more information please read + <ulink + url="http://www.openssl.org/docs/HOWTO/certificates.txt">http://www.openssl.org/docs/HOWTO/certificates.txt</ulink>. + </para> + + <para> + Now start (or restart) CouchDB. You should be able to connect to + it using HTTPS on port 6984: + </para> + +<programlisting> +shell> <userinput>curl https://127.0.0.1:6984/</userinput> +curl: (60) SSL certificate problem, verify that the CA cert is OK. Details: +error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed +More details here: http://curl.haxx.se/docs/sslcerts.html + +curl performs SSL certificate verification by default, using a "bundle" +of Certificate Authority (CA) public keys (CA certs). If the default +bundle file isn't adequate, you can specify an alternate file +using the --cacert option. +If this HTTPS server uses a certificate signed by a CA represented in +the bundle, the certificate verification probably failed due to a +problem with the certificate (it might be expired, or the name might +not match the domain name in the URL). +If you'd like to turn off curl's verification of the certificate, use +the -k (or --insecure) option. +</programlisting> + + <para> + Oh no what happened?! — Remember, clients will notify their + users that your certificate is self signed. + <command>curl</command> is the client in this case and it notifies + you. Luckily you trust yourself (don't you?) and you can specify + the <option>-k</option> option as the message reads: + </para> + +<programlisting> +shell> <userinput>curl -k https://127.0.0.1:6984/</userinput> +{"couchdb":"Welcome","version":"1.1.0"} +</programlisting> + + <para> + All done. + </para> + + </section> + + <section id="couchdb-release-1.1-httprange"> + + <title>HTTP Range Requests</title> + + <para> + HTTP allows you to specify byte ranges for requests. This allows + the implementation of resumable downloads and skippable audio and + video streams alike. Now this is available for all attachments + inside CouchDB. + </para> + + <para> + This is just a real quick run through how this looks under the + hood. Usually, you will have larger binary files to serve from + CouchDB, like MP3s and videos, but to make things a little more + obvious, I use a text file here (Note that I use the + <literal>application/octet-stream</literal> Content-Type instead + of <literal>text/plain</literal>). + </para> + +<programlisting> +shell> <userinput>cat file.txt </userinput> +My hovercraft is full of eels! +</programlisting> + + <para> + Now lets store this text file as an attachment in CouchDB. First, + we create a database: + </para> + +<programlisting> +shell> <userinput>curl -X PUT http://127.0.0.1:5984/test</userinput> +{"ok":true} +</programlisting> + + <para> + Then we create a new document and the file attachment in one go: + </para> + +<programlisting> +shell> <userinput>curl -X PUT http://127.0.0.1:5984/test/doc/file.txt -H "Content-Type: application/octet-stream" -d@file.txt</userinput> +{"ok":true,"id":"doc","rev":"1-287a28fa680ae0c7fb4729bf0c6e0cf2"} +</programlisting> + + <para> + Now we can request the whole file easily: + </para> + +<programlisting> +shell> <userinput>curl -X GET http://127.0.0.1:5984/test/doc/file.txt</userinput> +My hovercraft is full of eels! +</programlisting> + + <para> + But say we only want the first 13 bytes: + </para> + +<programlisting> +shell> <userinput>curl -X GET http://127.0.0.1:5984/test/doc/file.txt -H "Range: bytes=0-12"</userinput> +My hovercraft +</programlisting> + + <para> + HTTP supports many ways to specify single and even multiple byte + rangers. Read all about it in + <ulink + url="http://tools.ietf.org/html/rfc2616#section-14.27">RFC + 2616</ulink>. + </para> + + <note> + <para> + Databases that have been created with CouchDB 1.0.2 or earlier + will support range requests in 1.1.0, but they are using a + less-optimal algorithm. If you plan to make heavy use of this + feature, make sure to compact your database with CouchDB 1.1.0 + to take advantage of a better algorithm to find byte ranges. + </para> + </note> + + </section> + + <section id="couchdb-release-1.1-proxying"> + + <title>HTTP Proxying</title> + + <para> + The HTTP proxy feature makes it easy to map and redirect different + content through your CouchDB URL. The proxy works by mapping a + pathname and passing all content after that prefix through to the + configured proxy address. + </para> + + <para> + Configuration of the proxy redirect is handled through the + <literal>[httpd_global_handlers]</literal> section of the CouchDB + configuration file (typically <filename>local.ini</filename>). The + format is: + </para> + +<programlisting> +[httpd_global_handlers] +PREFIX = {couch_httpd_proxy, handle_proxy_req, <<"DESTINATION">>} + </programlisting> + + <para> + Where: + </para> + + <itemizedlist> + + <listitem> + <para> + <literal>PREFIX</literal> + </para> + + <para> + Is the string that will be matched. The string can be any + valid qualifier, although to ensure that existing database + names are not overridden by a proxy configuration, you can use + an underscore prefix. + </para> + </listitem> + + <listitem> + <para> + <literal>DESTINATION</literal> + </para> + + <para> + The fully-qualified URL to which the request should be sent. + The destination must include the <literal>http</literal> + prefix. The content is used verbatim in the original request, + so you can also forward to servers on different ports and to + specific paths on the target host. + </para> + </listitem> + + </itemizedlist> + + <para> + The proxy process then translates requests of the form: + </para> + +<programlisting> +http://couchdb:5984/PREFIX/path +</programlisting> + + <para> + To: + </para> + +<programlisting> +DESTINATION/path +</programlisting> + + <note> + <para> + Everything after <literal>PREFIX</literal> including the + required forward slash will be appended to the + <literal>DESTINATION</literal>. + </para> + </note> + + <para> + The response is then communicated back to the original client. + </para> + + <para> + For example, the following configuration: + </para> + +<programlisting> +<![CDATA[ +_google = {couch_httpd_proxy, handle_proxy_req, <<"http://www.google.com">>}]]> +</programlisting> + + <para> + Would forward all requests for + <literal>http://couchdb:5984/_google</literal> to the Google + website. + </para> + + <para> + The service can also be used to forward to related CouchDB + services, such as Lucene: + </para> + +<programlisting> + <![CDATA[ +[httpd_global_handlers] +_fti = {couch_httpd_proxy, handle_proxy_req, <<"http://127.0.0.1:5985">>}]]> +</programlisting> + + <note> + <para> + The proxy service is basic. If the request is not identified by + the <literal>DESTINATION</literal>, or the remainder of the + <literal>PATH</literal> specification is incomplete, the + original request URL is interpreted as if the + <literal>PREFIX</literal> component of that URL does not exist. + </para> + + <para> + For example, requesting + <literal>http://couchdb:5984/_intranet/media</literal> when + <filename>/media</filename> on the proxy destination does not + exist, will cause the request URL to be interpreted as + <literal>http://couchdb:5984/media</literal>. Care should be + taken to ensure that both requested URLs and destination URLs + are able to cope + </para> + </note> + + </section> + + <section id="couchdb-release-1.1-commonjs"> + + <title>Added CommonJS support to map functions</title> + + <para> + We didn't have CommonJS require in map functions because the + current CommonJS implementation is scoped to the whole design doc, + and giving views access to load code from anywhere in the design + doc would mean we'd have to blow away your view index any time you + changed anything. Having to rebuild views from scratch just + because you changed some CSS or a show function isn't fun, so we + avoided the issue by keeping CommonJS require out of map and + reduce altogether. + </para> + + <para> + The solution we came up with is to allow CommonJS inside map and + reduce funs, but only of libraries that are stored inside the + views part of the design doc. + </para> + + <para> + So you could continue to access CommonJS code in design_doc.foo, + from your list functions etc, but we'd add the ability to require + CommonJS modules within map and reduce, but only from + design_doc.views.lib + </para> + + <para> + There's no worry here about namespace collisions, as Couch just + plucks <literal>views.*.map</literal> and + <literal>views.*.reduce</literal> out of the design doc. So you + could have a view called <literal>lib</literal> if you wanted, and + still have CommonJS stored in <literal>views.lib.sha1</literal> + and <literal>views.lib.stemmer</literal> if you wanted. + </para> + + <para> + We simplified the implementation by enforcing that CommonJS + modules to be used in map functions be stored in views.lib. + </para> + + <para> + A sample design doc (taken from the test suite in Futon) is below: + </para> + +<programlisting> +{ + "views" : { + "lib" : { + "baz" : "exports.baz = 'bam';", + "foo" : { + "zoom" : "exports.zoom = 'yeah';", + "boom" : "exports.boom = 'ok';", + "foo" : "exports.foo = 'bar';" + } + }, + "commonjs" : { + "map" : "function(doc) { emit(null, require('views/lib/foo/boom').boom)}" + } + }, + "_id" : "_design/test" +} +</programlisting> + + <para> + The <literal>require()</literal> statement is relative to the + design document, but anything loaded form outside of + <literal>views/lib</literal> will fail. + </para> + + </section> + + <section id="couchdb-release-1.1-etag"> + + <title>More granular ETag support for views</title> + + <para> + ETags have been assigned to a map/reduce group (the collection of + views in a single design document). Any change to any of the + indexes for those views would generate a new ETag for all view + URL's in a single design doc, even if that specific view's results + had not changed. + </para> + + <para> + In CouchDB 1.1 each <literal>_view</literal> URL has it's own ETag + which only gets updated when changes are made to the database that + effect that index. If the index for that specific view does not + change, that view keeps the original ETag head (therefore sending + back 304 Not Modified more often). + </para> + + </section> + + <section id="couchdb-release-1.1-filters"> + + <title>Added built-in filters for <literal>_changes</literal>: + <literal>_doc_ids</literal> and <literal>_design</literal>.</title> + + <para> + The <literal>_changes</literal> feed can now be used to watch + changes to specific document ID's or the list of + <literal>_design</literal> documents in a database. If the + <literal>filters</literal> parameter is set to + <literal>_doc_ids</literal> a list of doc IDs can be passed in the + "doc_ids" as a JSON array. + </para> + + </section> + + <section id="couchdb-release-1.1-wildcards"> + + <title>Allow wildcards in vhosts definitions</title> + + <para> + Similar to the rewrites section of a <literal>_design</literal> + document, the new <literal>vhosts</literal> system uses variables + in the form of :varname or wildcards in the form of asterisks. The + variable results can be output into the resulting path as they are + in the rewriter. + </para> + + </section> + + <section id="couchdb-release-1.1-osprocess"> + + <title>OS Daemons</title> + + <para> + CouchDB now supports starting external processes. The support is + simple and enables CouchDB to start each configured OS daemon. If + the daemon stops at any point, CouchDB will restart it (with + protection to ensure regularly failing daemons are not repeatedly + restarted). + </para> + + <para> + The daemon starting process is one-to-one; for each each + configured daemon in the configuration file, CouchDB will start + exactly one instance. If you need to run multiple instances, then + you must create separate individual configurations. Daemons are + configured within the <literal>[os_daemons]</literal> section of + your configuration file (<filename>local.ini</filename>). The + format of each configured daemon is: + </para> + +<programlisting> +NAME = PATH ARGS + </programlisting> + + <para> + Where <literal>NAME</literal> is an arbitrary (and unique) name to + identify the daemon; <literal>PATH</literal> is the full path to + the daemon to be executed; <literal>ARGS</literal> are any + required arguments to the daemon. + </para> + + <para> + For example: + </para> + +<programlisting> +[os_daemons] +basic_responder = /usr/local/bin/responsder.js +</programlisting> + + <para> + There is no interactivity between CouchDB and the running process, + but you can use the OS Daemons service to create new HTTP servers + and responders and then use the new proxy service to redirect + requests and output to the CouchDB managed service. For more + information on proxying, see + <xref + linkend="couchdb-release-1.1-proxying"/>. For further + background on the OS Daemon service, see + <ulink url="http://davispj.com/2010/09/26/new-couchdb-externals-api.html">CouchDB + Externals API</ulink> + </para> + + </section> + + <section id="coudhdb-release-1.1-updateafter"> + + <title>Stale views and <literal>update_after</literal></title> + + <para> + Currently a view request can include the + <literal>stale=ok</literal> query argument, which allows the + contents of a stale view index to be used to produce the view + output. In order to trigger a build of the outdated view index, a + second view request must be made. + </para> + + <para> + To simplify this process, the <literal>update_after</literal> + value can be supplied to the <literal>stale</literal> query + argument. This triggers a rebuild of the view index after the + results of the view have been retrieved. + </para> + + </section> + + <section id="couchdb-release-1.1-socketoptions"> + + <title>Socket Options Configuration Setting</title> + + <para> + The socket options for the listening socket in CouchDB can now be + set within the CouchDB configuration file. The setting should be + added to the <literal>[httpd]</literal> section of the file using + the option name <literal>socket_options</literal>. The + specification is as a list of tuples. For example: + </para> + +<programlisting> +[httpd] +socket_options = [{recbuf, 262144}, {sndbuf, 262144}, {nodelay, true}] +</programlisting> + + <para> + The options supported are a subset of full options supported by + the TCP/IP stack. A list of the supported options are provided in + the + <ulink + url="http://www.erlang.org/doc/man/inet.html#setopts-2">Erlang + inet</ulink> documentation. + </para> + + </section> + + <section id="couchdb-release-1.1-serveroptions"> + + <title>Server Options Configuration Setting</title> + + <para> + Server options for the MochiWeb component of CouchDB can now be + added to the configuration file. Settings should be added to the + <literal>server_options</literal> option of the + <literal>[httpd]</literal> section of + <filename>local.ini</filename>. For example: + </para> + +<programlisting> +[httpd] +server_options = [{backlog, 128}, {acceptor_pool_size, 16}] + </programlisting> + + </section> + + <section id="couchdb-release-1.1-errormessages"> + + <title>Improved Error Messages</title> + + <para> + The errors reported when CouchDB is unable to read a required file + have been updated so that explicit information about the files and + problem can now be identified from the error message. The errors + report file permission access either when reading or writing to + configuration and database files. + </para> + + <para> + The error is raised both through the log file and the error + message returned through the API call as a JSON error message. For + example, when setting configuration values: + </para> + +<programlisting> +shell> <userinput>curl -H 'X-Couch-Persist: true' -X PUT http://couchdb:5984/_config/couchdb/delayed_commits -d '"false"'</userinput> +{"error":"file_permission_error","reason":"/etc/couchdb/local.ini"} + </programlisting> + + <para> + Errors will always be reported using the + <literal>file_permission_error</literal> error type. + </para> + + <para> + During startup permissions errors on key files are also reported + in the log with a descriptive error message and file location so + that permissions can be fixed before restart. + </para> + + </section> + + <section id="couchdb-release-1.1-microoptimizations"> + + <title>Multiple micro-optimizations when reading data.</title> + + <para> + We found a number of places where CouchDB wouldn't do the absolute + optimal thing when reading data and got rid of quite a few + inefficiencies. The problem with small optimizations all over the + place is that you may not notice them with every use-case, but we + sure hope you can see an improvement overall. + </para> + + </section> + +</article> |