### Example Database Shard Files Source: https://github.com/apache/couchdb/blob/main/src/docs/src/cluster/sharding.md Illustrates the file structure for database shards within a CouchDB installation. ```text data/shards/00000000-1fffffff/abc.1529362187.couch data/shards/20000000-3fffffff/abc.1529362187.couch data/shards/40000000-5fffffff/abc.1529362187.couch data/shards/60000000-7fffffff/abc.1529362187.couch data/shards/80000000-9fffffff/abc.1529362187.couch data/shards/a0000000-bfffffff/abc.1529362187.couch data/shards/c0000000-dfffffff/abc.1529362187.couch data/shards/e0000000-ffffffff/abc.1529362187.couch ``` -------------------------------- ### Define Reusable Elixir Setup Function Source: https://github.com/apache/couchdb/blob/main/test/elixir/README.md Defines a shared setup function for starting HTTPD and creating an admin user. Promotes code reuse in test setups. ```elixir defmodule Foo do alias Couch.Test.Setup.Step def httpd_with_admin(setup) do setup |> Step.Start.new(:start, extra_apps: [:chttpd]) |> Step.User.new(:admin, roles: [:server_admin]) end end ``` -------------------------------- ### Accept Header Example (JSON) Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/basics.md Demonstrates a GET request with the Accept header set to application/json, ensuring a JSON response. ```APIDOC ## GET /recipes ### Description This example shows a GET request to the /recipes endpoint with the Accept header explicitly set to application/json, ensuring the response Content-Type is also JSON. ### Method GET ### Endpoint /recipes ### Parameters #### Request Headers - **Accept** (string) - Required - Specifies the desired response content type, e.g., `application/json`. ### Request Example ```http GET /recipes HTTP/1.1 Host: couchdb:5984 Accept: application/json ``` ### Response #### Success Response (200) - **Content-Type** (application/json) - The content type of the response, matching the Accept header. #### Response Example ```http HTTP/1.1 200 OK Server: CouchDB (Erlang/OTP) Date: Thu, 13 Jan 2013 13:40:11 GMT Content-Type: application/json Content-Length: 227 Cache-Control: must-revalidate ``` ``` -------------------------------- ### Successful GET /_session Response Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/server/authn.md Example response for a successful GET /_session request. Includes user context, authentication info, and configured handlers. ```http HTTP/1.1 200 OK Cache-Control: must-revalidate Content-Length: 175 Content-Type: application/json Date: Fri, 09 Aug 2013 20:27:45 GMT Server: CouchDB (Erlang/OTP) Set-Cookie: AuthSession=cm9vdDo1MjA1NTBDMTqmX2qKt1KDR--GUC80DQ6-Ew_XIw; Version=1; Path=/; HttpOnly { "info": { "authenticated": "cookie", "authentication_db": "_users", "authentication_handlers": [ "cookie", "default" ] }, "ok": true, "userCtx": { "name": "root", "roles": [ "_admin" ] } } ``` -------------------------------- ### Accept Header Example (Default) Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/basics.md Demonstrates a GET request without an explicit Accept header, showing the default response Content-Type. ```APIDOC ## GET /recipes ### Description This example shows a basic GET request to the /recipes endpoint without specifying an Accept header. ### Method GET ### Endpoint /recipes ### Request Example ```http GET /recipes HTTP/1.1 Host: couchdb:5984 Accept: */* ``` ### Response #### Success Response (200) - **Content-Type** (text/plain;charset=utf-8) - The content type of the response. #### Response Example ```http HTTP/1.1 200 OK Server: CouchDB (Erlang/OTP) Date: Thu, 13 Jan 2011 13:39:34 GMT Content-Type: text/plain;charset=utf-8 Content-Length: 227 Cache-Control: must-revalidate ``` ``` -------------------------------- ### QuickJS Scanner Log Output Source: https://github.com/apache/couchdb/blob/main/src/docs/src/best-practices/jsdevel.md Example log output indicating the start and completion of a QuickJS scanner session. ```text couch_quickjs_scanner_plugin s:1725559802-c615220453e6 starting ... couch_quickjs_scanner_plugin s:1725559802-c615220453e6 completed ``` -------------------------------- ### Finish CouchDB Cluster Setup Source: https://github.com/apache/couchdb/blob/main/src/docs/src/setup/cluster.md Run this command on the setup coordination node after all nodes have been added to finalize the cluster setup and add system databases. ```bash curl -X POST -H "Content-Type: application/json" http://admin:password@:5984/_cluster_setup -d '{"action": "finish_cluster"}' ``` -------------------------------- ### Install CouchDB Snap Source: https://github.com/apache/couchdb/blob/main/src/docs/src/install/snap.md Installs the CouchDB snap package. Ensure snapd is installed first. ```sh sudo snap install couchdb ``` -------------------------------- ### Querying a Partitioned Search Index via Command Line Source: https://github.com/apache/couchdb/blob/main/src/docs/src/ddocs/search.md This command-line example uses curl to query a partitioned search index, mirroring the functionality of the HTTP GET request. ```sh curl https://$HOST:5984/$DATABASE/_partition/$PARTITION_KEY/_design/$DDOC/ _search/$INDEX_NAME?include_docs=true\&query="*:*"\&limit=1 \ ``` -------------------------------- ### Start CouchDB Service Source: https://github.com/apache/couchdb/blob/main/src/docs/src/install/freebsd.md Start the CouchDB service after enabling it in rc.conf. Use 'onestart' to start it ad-hoc if not yet enabled. ```bash service couchdb3 start ``` -------------------------------- ### Install CouchDB with Homebrew Source: https://github.com/apache/couchdb/blob/main/src/docs/src/install/mac.md Use Homebrew to install the latest version of CouchDB. Ensure Homebrew and its formulae are up-to-date before installing. ```bash brew update brew install couchdb ``` -------------------------------- ### Integrate Shared Setup in Elixir Tests Source: https://github.com/apache/couchdb/blob/main/test/elixir/README.md Demonstrates how to integrate shared setup functions like `httpd_with_admin` into a test suite. Manages context and setup execution. ```elixir defmodule Couch.Test.CRUD do use Couch.Test.ExUnit.Case alias Couch.Test.Utils alias Couch.Test.Setup alias Couch.Test.Setup.Step def with_db(context, setup) do setup = setup |> Setup.Common.httpd_with_db() |> Setup.run() context = Map.merge(context, %{ db_name: setup |> Setup.get(:db) |> Step.Create.DB.name(), base_url: setup |> Setup.get(:start) |> Step.Start.clustered_url(), user: setup |> Setup.get(:admin) |> Step.User.name() }) {context, setup} end describe "Database CRUD using Fabric API" do @describetag setup: &__MODULE__.with_db/2 test "Create DB", ctx do IO.puts("base_url: #{ctx.base_url}") IO.puts("admin: #{ctx.user}") IO.puts("db_name: #{ctx.db_name}") end end end ``` -------------------------------- ### Get Cluster Setup State Source: https://github.com/apache/couchdb/blob/main/src/setup/README.md Retrieve the current state of the cluster setup process. This is a GET request to the `/_cluster_setup` endpoint. ```http GET /_cluster_setup {"state": "cluster_disabled"} ``` ```http GET /_cluster_setup {"state":"cluster_enabled","nodes":[]} ``` ```http GET /_cluster_setup {"state":"cluster_finished","nodes":["node a", "node b", ...]} ``` -------------------------------- ### Clone and Test CouchDB Setup Source: https://github.com/apache/couchdb/blob/main/src/setup/README.md Steps to clone the CouchDB repository, checkout the setup branch, configure, build, and run a test cluster. Includes instructions for running test scripts and resetting instances. ```bash git clone https://git-wip-us.apache.org/repos/asf/couchdb.git cd couchdb git checkout setup ./configure make dev/run --no-join -n 2 --admin a:b ``` ```bash src/setup/test/t.sh ``` ```bash rm -rf dev/lib/ dev/logs/ dev/run --no-join -n 2 --admin a:b ``` -------------------------------- ### GET /db/_changes Request Example Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/database/changes.md Example of a GET request to the _changes endpoint with the 'all_docs' style parameter to retrieve all document revisions. ```http GET /db/_changes?style=all_docs HTTP/1.1 Accept: application/json Host: localhost:5984 ``` -------------------------------- ### Build CouchDB Documentation Source: https://github.com/apache/couchdb/blob/main/src/docs/README.md Install Python 3 and pip, then use these commands to set up a virtual environment, install dependencies, and build the HTML documentation. ```sh python3 -m venv .venv source .venv/bin/activate pip3 install -r requirements.txt make html # builds the docs make check # syntax checks the docs ``` -------------------------------- ### FoundationDB Skip List Setup and Constants Source: https://github.com/apache/couchdb/blob/main/src/docs/rfcs/012-fdb-reduce.md Initializes FoundationDB connection, sets API version, and defines constants for the skip list implementation. Includes setup instructions for running locally. ```javascript /* To run locally npm install foundationdb node skiplist.js */ const assert = require('assert'); const util = require('util'); const fdb = require('foundationdb'); const ks = require('foundationdb').keySelector; // CONSTANTS const SHOULD_LOG = false; const PREFIX = 'skiplist'; const MAX_LEVELS = 6; const LEVEL_FAN_POW = 1; // 2^X per level or (1 / 2^X) less than previous level const END = 0xFF; fdb.setAPIVersion(600); // Must be called before database is opened const db = fdb.openSync() .at(PREFIX) // database prefix for all operations .withKeyEncoding(fdb.encoders.tuple) .withValueEncoding(fdb.encoders.json); // automatically encode & decode values using JSON // Data model // (level, key) = reduce_value const log = (...args) => { if (!SHOULD_LOG) { return; } console.log(...args); } ``` -------------------------------- ### GET /_all_dbs Response Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/server/common.md Example JSON response for the GET /_all_dbs request, listing database names. The Content-Type will be application/json. ```json [ "_users", "contacts", "docs", "invoices", "locations" ] ``` -------------------------------- ### Basic local.ini Configuration Example Source: https://github.com/apache/couchdb/blob/main/src/docs/src/config/intro.md This is a standard way to set parameters in the local.ini file. It demonstrates section definitions, parameter specifications, and inline comments. ```ini ; This is a comment [section] param = value ; inline comments are allowed ``` -------------------------------- ### Start the Nouveau Server Source: https://github.com/apache/couchdb/blob/main/src/docs/src/install/nouveau.md Execute this command to start the Nouveau server. Ensure all necessary JAR files are in the same directory as nouveau.jar. ```bash java -jar /path/to/nouveau.jar server /path/to/nouveau.yaml ``` -------------------------------- ### Get Target Information Response Source: https://github.com/apache/couchdb/blob/main/src/docs/src/replication/protocol.md Example JSON response from a GET request to a target database. Note that `update_seq` can be a string for large databases. ```json { "compact_running": false, "db_name": "target", "disk_format_version": 5, "doc_count": 1832, "doc_del_count": 1, "instance_start_time": "0", "purge_seq": 0, "sizes": { "active": 50829452, "disk": 77001455, "external": 60326450 }, "update_seq": "1841-g1AAAADveJzLYWBgYMlgTmGQT0lKzi9KdUhJMtbLSs1LLUst0k" } ``` -------------------------------- ### Set up Java and SBT for building Clouseau from source Source: https://github.com/apache/couchdb/blob/main/README-DEV.rst Install specific versions of Java and SBT using 'asdf' and set the corresponding CLOUSEAU_JAVA_HOME and CLOUSEAU_SBT_HOME environment variables. This is required when building Clouseau from source for testing. ```bash asdf install java openjdk-21 ``` ```bash asdf plugin add sbt ``` ```bash asdf install sbt 1.11.7 ``` ```bash export CLOUSEAU_JAVA_HOME=$(asdf where java openjdk-21) ``` ```bash export CLOUSEAU_SBT_HOME=$(asdf where sbt 1.11.7) ``` -------------------------------- ### GET /_scheduler/jobs Response Example Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/server/common.md This JSON structure represents the response from a GET request to the /_scheduler/jobs endpoint, detailing active replication jobs. ```json { "jobs": [ { "continuous": false, "doc_id": null, "doc_write_batch": 1, "last_seq": "1-abcdef1234567890abcdef1234567890", "replication_id": "rep-12345", "source": "http://myserver.com/foo", "target": "http://adm:*****@localhost:15984/cdyno-0000002/", "worker": "node1@127.0.0.1" } ], "offset": 0, "total_rows": 1 } ``` -------------------------------- ### Setup and Indexing Database with Nouveau Source: https://github.com/apache/couchdb/blob/main/extra/nouveau/README.md This script sets up a CouchDB database with a Nouveau index definition and populates it with sample data. It demonstrates creating, deleting, and updating documents, and defining index analyzers. ```shell #!/bin/sh URL="http://foo:bar@127.0.0.1:15984/foo" curl -X DELETE "$URL" curl -X PUT "$URL?n=3&q=16" curl -X PUT "$URL/_design/foo" -d '{"nouveau":{"bar":{"default_analyzer":"standard", "field_analyzers":{"foo":"english"}, "index":"function(doc) { index(\"string\", \"foo\", \"bar\"); }"}}}' # curl "$URL/_index" -Hcontent-type:application/json -d '{"type":"nouveau", "index": {"fields": [{"name": \"bar\", \"type\":\"number\"}]}}' for I in {1..5}; do DOCID=$RANDOM DOCID=$[ $DOCID % 100000 ] BAR=$RANDOM BAR=$[ $BAR % 100000 ] curl -X PUT "$URL/doc$DOCID" -d "{\"bar\": $BAR}" done while true; do curl 'foo:bar@localhost:15984/foo/_design/foo/_nouveau/bar?q=*:*' done ``` -------------------------------- ### Get Source Information Response Source: https://github.com/apache/couchdb/blob/main/src/docs/src/replication/protocol.md Example JSON response from a GET request to a source database. The `update_seq` field is crucial for replication progress tracking. ```json { "committed_update_seq": 61772, "compact_running": false, "db_name": "source", "disk_format_version": 6, "doc_count": 41961, "doc_del_count": 3807, "instance_start_time": "0", "purge_seq": 0, "sizes": { "active": 70781613961, "disk": 79132913799, "external": 72345632950 }, "update_seq": 61772 } ``` -------------------------------- ### Get Cluster Setup Status Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/server/common.md Retrieves the current state of the node or cluster as part of the cluster setup wizard. It can optionally ensure specific system databases exist. ```APIDOC ## GET /_cluster_setup ### Description Returns the status of the node or cluster, per the cluster setup wizard. ### Method GET ### Endpoint /_cluster_setup ### Parameters #### Query Parameters - **ensure_dbs_exist** (array) - Optional - List of system databases to ensure exist on the node/cluster. Defaults to `["_users","_replicator"]`. ### Response #### Success Response (200) - **state** (string) - Current `state` of the node and/or cluster. Possible values include `cluster_disabled`, `single_node_disabled`, `single_node_enabled`, `cluster_enabled`, `cluster_finished`. ### Request Example ```http GET /_cluster_setup HTTP/1.1 Accept: application/json Host: localhost:5984 ``` ### Response Example ```json { "state": "cluster_enabled" } ``` ``` -------------------------------- ### Query Syntax Examples Source: https://github.com/apache/couchdb/blob/main/src/docs/src/ddocs/nouveau.md Examples demonstrating the syntax for constructing search queries. ```APIDOC ## Query Syntax Examples ### Basic Queries - `class:bird` - `l*` ### Combined Queries - `class:bird AND diet:carnivore` - `l* AND diet:herbivore` - `min_length:[1 TO 3] AND diet:herbivore` - `diet:herbivore AND min_length:[* TO 2]` - `class:mammal AND min_length:[1.5 TO *]` - `latin_name:"Meles meles"` - `diet:(herbivore OR omnivore) AND class:mammal` - `*:*` (Return all results) ### Fuzzy Search - `look~` (finds terms like 'book' and 'took') ### Operators - `AND`, `+`, `OR`, `NOT`, `-` ``` -------------------------------- ### Create Index with All Query Parameters Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/database/find.md This example demonstrates creating a JSON index using all available query parameters, including partial filter selectors, specific fields, design document, name, type, and partitioned status. ```http POST /db/_index HTTP/1.1 Content-Type: application/json Content-Length: 396 Host: localhost:5984 { "index": { "partial_filter_selector": { "year": { "$gt": 2010 }, "limit": 10, "skip": 0 }, "fields": [ "_id", "_rev", "year", "title" ] }, "ddoc": "example-ddoc", "name": "example-index", "type": "json", "partitioned": false } ``` -------------------------------- ### GET /_dbs_info Response Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/server/common.md Example JSON response for the GET /_dbs_info request, providing details for each database including update sequence, sizes, and cluster information. The Content-Type will be application/json. ```json [ { "key": "animals", "info": { "db_name": "animals", "update_seq": "52232", "sizes": { "file": 1178613587, "external": 1713103872, "active": 1162451555 }, "purge_seq": 0, "doc_del_count": 0, "doc_count": 52224, "disk_format_version": 6, "compact_running": false, "cluster": { "q": 8, "n": 3, "w": 2, "r": 2 }, "instance_start_time": "0" } } ] ``` -------------------------------- ### Bulk Get Response for Conflicted Document Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/database/bulk-api.md This is a partial response example for a bulk get request. It shows the structure for a single document result, which can contain either the document data (`ok`) or an error. ```json { "results": [ { "id": "a", "docs": [ { ``` -------------------------------- ### Create Database and Add Documents Source: https://github.com/apache/couchdb/blob/main/src/docs/src/cluster/sharding.md Demonstrates creating a new database and adding two documents to it using curl commands. ```bash $ curl -X PUT $COUCH_URL:5984/mydb {"ok":true} ``` ```bash $ curl -X PUT $COUCH_URL:5984/mydb/joan -d '{"loves":"cats"}' {"ok":true,"id":"joan","rev":"1-cc240d66a894a7ee7ad3160e69f9051f"} ``` ```bash $ curl -X PUT $COUCH_URL:5984/mydb/robert -d '{"loves":"dogs"}' {"ok":true,"id":"robert","rev":"1-4032b428c7574a85bc04f1f271be446e"} ``` -------------------------------- ### Get Cluster Setup Status Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/server/common.md Use this endpoint to check the current state of the node or cluster setup. The `state` field indicates whether the node is disabled, enabled as a single node, or part of a cluster. ```http GET /_cluster_setup HTTP/1.1 Accept: application/json Host: localhost:5984 ``` ```http HTTP/1.1 200 OK X-CouchDB-Body-Time: 0 X-Couch-Request-ID: 5c058bdd37 Server: CouchDB/2.1.0-7f17678 (Erlang OTP/17) Date: Sun, 30 Jul 2017 06:33:18 GMT Content-Type: application/json Content-Length: 29 Cache-Control: must-revalidate {"state":"cluster_enabled"} ``` -------------------------------- ### CouchDB Snap Configuration Example Source: https://github.com/apache/couchdb/blob/main/src/docs/src/install/snap.md Example configuration stanza for CouchDB snap, specifying data and view directories. This is typically placed in `/var/snap/couchdb/current/etc/local.ini`. ```ini [couchdb] ;max_document_size = 4294967296 ; bytes ;os_process_timeout = 5000 database_dir = /var/snap/couchdb/common/data view_index_dir = /var/snap/couchdb/common/data ``` -------------------------------- ### Enable Cluster Setup Source: https://github.com/apache/couchdb/blob/main/src/setup/README.md Initiate the cluster setup process by sending a POST request with the `enable_cluster` action to `/_cluster_setup`. This transitions the state from `cluster_disabled` to `cluster_enabled`. ```http POST /_cluster_setup {"action":"enable_cluster"...} ``` -------------------------------- ### GET /db/_changes Response Example Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/database/changes.md Example JSON response from the _changes endpoint, showing the last sequence number, pending changes, and a list of recent changes including document IDs and revision information. ```json { "last_seq": "5-g1AAAAIreJyVkEsKwjAURZ-toI5cgq5A0sQ0OrI70XyppcaRY92J7kR3ojupaSPUUgotgRd4yTlwbw4A0zRUMLdnpaMkwmyF3Ily9xBwEIuiKLI05KOTW0wkV4rruP29UyGWbordzwKVxWBNOGMKZhertDlarbr5pOT3DV4gudUC9-MPJX9tpEAYx4TQASns2E24ucuJ7rXJSL1BbEgf3vTwpmedCZkYa7Pulck7Xt7x_usFU2aIHOD4eEfVTVA5KMGUkqhNZV-8_o5i", "pending": 0, "results": [ { "changes": [ { "rev": "2-7051cbe5c8faecd085a3fa619e6e6337" } ], "id": "6478c2ae800dfc387396d14e1fc39626", "seq": "3-g1AAAAG3eJzLYWBg4MhgTmHgz8tPSTV0MDQy1zMAQsMcoARTIkOS_P___7MSGXAqSVIAkkn2IFUZzIkMuUAee5pRqnGiuXkKA2dpXkpqWmZeagpu_Q4g_fGEbEkAqaqH2sIItsXAyMjM2NgUUwdOU_JYgCRDA5ACGjQfn30QlQsgKvcjfGaQZmaUmmZClM8gZhyAmHGfsG0PICrBPmQC22ZqbGRqamyIqSsLAAArcXo" }, { "changes": [ { "rev": "3-7379b9e515b161226c6559d90c4dc49f" } ], "deleted": true, "id": "5bbc9ca465f1b0fcd62362168a7c8831", ``` -------------------------------- ### POST /_cluster_setup Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/server/common.md Configure a node as a single (standalone) node, as part of a cluster, or finalise a cluster. ```APIDOC ## POST /_cluster_setup ### Description Configure a node as a single (standalone) node, as part of a cluster, or finalise a cluster. ### Method POST ### Endpoint /_cluster_setup ### Parameters #### Request Body - **action** (string) - Required - Specifies the cluster setup action to perform. Possible values: `enable_single_node`, `enable_cluster`, `add_node`, `finish_cluster`. - **bind_address** (string) - Optional - The IP address to which to bind the current node. `0.0.0.0` binds to all interfaces. (Used with `enable_cluster` and `enable_single_node`) - **username** (string) - Optional - The username of the server-level administrator to create or the remote server's administrator username. (Used with `enable_cluster`, `enable_single_node`, and `add_node`) - **password** (string) - Optional - The password for the server-level administrator to create or the remote server's administrator username. (Used with `enable_cluster`, `enable_single_node`, and `add_node`) - **port** (number) - Optional - The TCP port to bind this node or a remote node. (Used with `enable_cluster`, `enable_single_node`, and `add_node`) - **node_count** (number) - Optional - The total number of nodes to be joined into the cluster. (Used with `enable_cluster` only) - **remote_node** (string) - Optional - The IP address of the remote node to setup as part of this cluster's list of nodes. (Used with `enable_cluster` only) - **remote_current_user** (string) - Optional - The username of the server-level administrator authorized on the remote node. (Used with `enable_cluster` only) - **remote_current_password** (string) - Optional - The password of the server-level administrator authorized on the remote node. (Used with `enable_cluster` only) - **host** (string) - Optional - The remote node IP of the node to add to the cluster. (Used with `add_node` only) - **ensure_dbs_exist** (array) - Optional - List of system databases to ensure exist on the node/cluster. Defaults to `["_users","_replicator"]`. ### Status Codes - 200 OK - Request completed successfully - 401 Unauthorized - Unauthorized request to a protected API - 403 Forbidden - Insufficient permissions / Too many requests with invalid credentials ``` -------------------------------- ### Get CouchDB Snap Info Source: https://github.com/apache/couchdb/blob/main/src/docs/src/install/snap.md Displays information about the installed CouchDB snap, including available channels. ```sh snap info couchdb ``` -------------------------------- ### Get Cluster Membership Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/server/common.md Retrieves the nodes participating in the cluster and all known nodes. Useful for cluster setup. ```http GET /_membership HTTP/1.1 Accept: application/json Host: localhost:5984 ``` ```http HTTP/1.1 200 OK Cache-Control: must-revalidate Content-Type: application/json Date: Sat, 11 Jul 2015 07:02:41 GMT Server: CouchDB (Erlang/OTP) Content-Length: 142 { "all_nodes": [ "node1@127.0.0.1", "node2@127.0.0.1", "node3@127.0.0.1" ], "cluster_nodes": [ "node1@127.0.0.1", "node2@127.0.0.1", "node3@127.0.0.1" ] } ``` -------------------------------- ### Install CouchDB using pkg Source: https://github.com/apache/couchdb/blob/main/src/docs/src/install/freebsd.md Use this command to install CouchDB from pre-built binary packages. ```bash pkg install couchdb3 ``` -------------------------------- ### Simple Query Examples for FoundationDB Source: https://github.com/apache/couchdb/blob/main/src/docs/rfcs/012-fdb-reduce.md Demonstrates various simple query scenarios, including different group levels and key ranges, to verify accuracy. ```javascript const simpleQueries = async () => { let result = {}; result = await query({group_level: 0}); assert.deepEqual(result, { rows: [{ key: null, value: 68 }] }); result = await query({group_level:0, startkey: [2018, 3, 2]}); assert.deepEqual(result, { rows: [{ key: null, value: 31 }] }); result = await query({ group_level:0, startkey: [2018, 3, 2], endkey: [2019, 5, 1] }); assert.deepEqual(result, { rows: [{ key: null, value: 31 }] }); result = await query({ group_level: 0, startkey: [2018, 03, 2], endkey: [2019, 03, 2], }) assert.deepEqual(result, { rows: [{ key: null, value: 18 }] }); result = await query({ group_level: 1, startkey: [2017, 4, 1], endkey: [2018, 3, 1], }) assert.deepEqual(result, { rows: [ { key: [2017], value: 22 }, { key: [2018], value: 6 } ] }); result = await query({ group_level: 1, startkey: [2017, 4, 1], endkey: [2019, 03, 2], }) assert.deepEqual(result, { rows: [ { key: [2017], value: 22 }, { key: [2018], value: 20 }, { key: [2019], value: 4 } ] }); result = await query({ group_level: 1, startkey: [2017, 4, 1], endkey: [2019, 05, 1], }) assert.deepEqual(result, { rows: [ { key: [2017], value: 22 }, { key: [2018], value: 20 }, { key: [2019], value: 17 } ] }); result = await query({ group: true, startkey: [2018, 5, 1], endkey: [2019, 4, 1], }); assert.deepEqual(result, {rows: [ {key: [2018,5,1], value: 7}, {key: [2019,3,1], value: 4}, {key: [2019,4,1], value: 6} ]}) log('SIMPLE DONE'); }; ``` -------------------------------- ### Using Key Parameters Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/ddoc/views.md Explains the usage of `key`, `keys`, `start_key`, and `end_key` for precise view querying, including compatibility and precedence rules. ```APIDOC ## Querying Views with Key Parameters ### Description This section details how to use `key`, `keys`, `start_key`, and `end_key` to query CouchDB views. It covers single and multi-element `keys` and their interaction with other key parameters and `group=true`. ### Method GET ### Endpoint /db/_design/ddoc/_view/reduce ### Query Parameters - **key** (string) - Optional - Filters results to a single specific key. Equivalent to `start_key=$key&end_key=$key`. - **keys** (array) - Optional - Filters results based on a list of keys. For reduce views, requires `group=true` for multi-element arrays. - **start_key** (string) - Optional - The lower bound of the key range. - **end_key** (string) - Optional - The upper bound of the key range. - **group** (boolean) - Optional - Required when using multi-element `keys` with reduce views. ### Request Examples #### Using `key` ```bash curl http://adm:pass@127.0.0.1:5984/db/_design/ddoc/_view/reduce'?key="a"' ``` #### Using single-element `keys` ```bash curl http://adm:pass@127.0.0.1:5984/db/_design/ddoc/_view/reduce'?keys="["a"]"' ``` #### Using multi-element `keys` with `group=true` ```bash curl http://adm:pass@127.0.0.1:5984/db/_design/ddoc/_view/reduce'?keys=\"a","c\"]&group=true' ``` #### Using `key` with `endkey` (equivalent to `start_key=a` and `end_key=b`) ```bash curl http://adm:pass@127.0.0.1:5984/db/_design/ddoc/_view/reduce'?key="a"&endkey="b"' ``` #### Using `endkey` with `key` (equivalent to `start_key=a` and `end_key=a`) ```bash curl http://adm:pass@127.0.0.1:5984/db/_design/ddoc/_view/reduce'?endkey="b"&key="a"' ``` #### Using `endkey` with `keys` (single element) ```bash curl http://adm:pass@127.0.0.1:5984/db/_design/ddoc/_view/reduce'?endkey="b"&keys=\"a\"' ``` ### Response #### Success Response (200) - **rows** (array) - Contains the view results, with keys and values. #### Response Example (for `key="a"`) ```json { "rows": [ { "key": null, "value": 1 } ] } ``` #### Response Example (for `keys=["a","c"]&group=true`) ```json { "rows": [ { "key": "a", "value": 1 }, { "key": "c", "value": 3 } ] } ``` ### Error Handling - **query_parse_error**: Returned when `keys` is used with reduce views without `group=true`, or when `keys` is used with `key`, `start_key`, or `end_key`. ``` -------------------------------- ### Creating a Database With Correct Admin Credentials Source: https://github.com/apache/couchdb/blob/main/src/docs/src/intro/security.md This command shows how to successfully create a database by including valid admin username and password in the URL for basic authentication. ```bash HOST="http://anna:secret@127.0.0.1:5984" curl -X PUT $HOST/somedatabase {"ok":true} ``` -------------------------------- ### Get Cluster Membership Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/server/common.md Displays the nodes that are part of the cluster and all nodes the current node is aware of. Useful for cluster setup and management. ```APIDOC ## GET /_membership ### Description Displays the nodes that are part of the cluster as `cluster_nodes`. The field `all_nodes` displays all nodes this node knows about, including the ones that are part of the cluster. The endpoint is useful when setting up a cluster. ### Method GET ### Endpoint /_membership ### Request Headers - Accept (application/json, text/plain) ### Response Headers - Content-Type (application/json, text/plain; charset=utf-8) ### Status Codes - 200 OK - Request completed successfully - 401 Unauthorized - Unauthorized request to a protected API - 403 Forbidden - Insufficient permissions / Too many requests with invalid credentials ### Request Example ```http GET /_membership HTTP/1.1 Accept: application/json Host: localhost:5984 ``` ### Response Example ```json { "all_nodes": [ "node1@127.0.0.1", "node2@127.0.0.1", "node3@127.0.0.1" ], "cluster_nodes": [ "node1@127.0.0.1", "node2@127.0.0.1", "node3@127.0.0.1" ] } ``` ``` -------------------------------- ### Verify Cluster Setup Source: https://github.com/apache/couchdb/blob/main/src/docs/src/setup/cluster.md Retrieves the current state of the cluster setup process. ```APIDOC ## Verify Cluster Setup ### Description Checks the status of the cluster setup. ### Method GET ### Endpoint `/_cluster_setup` ### Response #### Success Response (200) - **state** (string) - The current state of the cluster setup (e.g., `"cluster_finished"`) ``` -------------------------------- ### GET /_db_updates Request Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/server/common.md Example HTTP request to retrieve database update events. Ensure the Accept header is set to application/json. ```http GET /_db_updates HTTP/1.1 Accept: application/json Host: localhost:5984 ``` -------------------------------- ### GET /_dbs_info Request Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/server/common.md Example HTTP request to retrieve information about all databases in a CouchDB instance. The Accept header should be set to application/json. ```http GET /_dbs_info HTTP/1.1 Accept: application/json Host: localhost:5984 ``` -------------------------------- ### Finish Cluster Setup Source: https://github.com/apache/couchdb/blob/main/src/docs/src/setup/cluster.md This command is run on the setup coordination node to finalize the cluster configuration and add system databases. ```APIDOC ## Finish Cluster Setup ### Description Completes the cluster setup process and initializes system databases. ### Method POST ### Endpoint `/_cluster_setup` ### Request Body - **action** (string) - Required - Must be `"finish_cluster"` ### Request Example ```json { "action": "finish_cluster" } ``` ``` -------------------------------- ### Install runit Package Source: https://github.com/apache/couchdb/blob/main/src/docs/src/install/unix.md Installs the runit package using apt-get on Ubuntu systems. ```sh sudo apt-get install runit ``` -------------------------------- ### JWT Authentication Request Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/server/authn.md Example HTTP GET request to the _session endpoint, including the Authorization header with a JWT token for authentication. ```http GET /_session HTTP/1.1 Host: localhost:5984 Accept: application/json Content-Type: application/json; charset=utf-8 Authorization: Bearer ``` -------------------------------- ### Test Single-Node Setup Script Source: https://github.com/apache/couchdb/blob/main/src/setup/README.md Execute the `t-single_node.sh` script in a separate terminal to verify the single-node setup. ```bash $ src/setup/test/t-single_node.sh ``` -------------------------------- ### Finish Cluster Setup Source: https://github.com/apache/couchdb/blob/main/src/setup/README.md Complete the cluster setup process by sending a POST request with the `finish_cluster` action. This transitions the state to `cluster_finished`. ```http POST /_cluster_setup {"action":"finish_cluster"} ``` -------------------------------- ### GET /_all_dbs Request Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/server/common.md Example HTTP request to retrieve a list of all databases in a CouchDB instance. Ensure the Accept header is set to application/json. ```http GET /_all_dbs HTTP/1.1 Accept: application/json Host: localhost:5984 ``` -------------------------------- ### Bulk GET Response Example Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/database/bulk-api.md Illustrates the structure of a successful response from the _bulk_get endpoint, showing retrieved documents or errors for missing ones. ```json { "results": [ { "ok": { "_id": "a", "_rev": "1-23202479633c2b380f79507a776743d5", "a": 1 } }, { "ok": { "_id": "a", "_rev": "1-967a00dff5e02add41819138abb3284d" } } ] } ``` -------------------------------- ### Create a Partitioned Database Source: https://github.com/apache/couchdb/blob/main/src/docs/src/partitioned-dbs/index.md Use the `partitioned=true` query parameter when creating a new database to enable partitioning. ```bash shell> curl -X PUT 'http://adm:pass@127.0.0.1:5984/my_new_db?partitioned=true' {"ok":true} ``` -------------------------------- ### Default View Sorting Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/ddoc/views.md This example shows a GET request to a view endpoint without any sorting parameters, demonstrating the default UTF-8 sorting order. ```APIDOC ## GET /db/_design/test/_view/sorting ### Description Retrieves view results sorted according to CouchDB's default UTF-8 sorting rules. ### Method GET ### Endpoint /db/_design/test/_view/sorting ### Parameters #### Query Parameters - **descending** (boolean) - Optional - If true, reverses the sort order. ### Request Example ```http GET /db/_design/test/_view/sorting HTTP/1.1 Accept: application/json Host: localhost:5984 ``` ### Response #### Success Response (200) - **offset** (integer) - The offset where the returned rows start. - **rows** (array) - An array of view result objects, each containing 'id', 'key', and 'value'. - **total_rows** (integer) - The total number of rows in the view. #### Response Example ```json { "offset": 0, "rows": [ { "id": "dummy-doc", "key": null, "value": null }, { "id": "dummy-doc", "key": false, "value": null }, { "id": "dummy-doc", "key": true, "value": null }, { "id": "dummy-doc", "key": 0, "value": null }, { "id": "dummy-doc", "key": 1, "value": null }, { "id": "dummy-doc", "key": 10, "value": null }, { "id": "dummy-doc", "key": 42, "value": null }, { "id": "dummy-doc", "key": "10", "value": null }, { "id": "dummy-doc", "key": "hello", "value": null }, { "id": "dummy-doc", "key": "Hello", "value": null }, { "id": "dummy-doc", "key": "\u043f\u0440\u0438\u0432\u0435\u0442", "value": null }, { "id": "dummy-doc", "key": [], "value": null }, { "id": "dummy-doc", "key": [ 1, 2, 3 ], "value": null }, { "id": "dummy-doc", "key": [ 2, 3 ], "value": null }, { "id": "dummy-doc", "key": [ 3 ], "value": null }, { "id": "dummy-doc", "key": {}, "value": null }, { "id": "dummy-doc", "key": { "foo": "bar" }, "value": null } ], "total_rows": 17 } ``` ``` -------------------------------- ### Setup Skip List and Insert Initial Key-Value Pairs Source: https://github.com/apache/couchdb/blob/main/src/docs/rfcs/012-fdb-reduce.md Initializes the skip list by inserting a base key '0' with value 0 at all levels, then inserts a predefined set of key-value pairs. ```javascript const create = async () => { await db.doTransaction(async tn => { for(let level = 0; level <= MAX_LEVELS; level++) { await insertAtLevel(tn, '0', 0, level); } }); log('setup done'); for ([key, val] of kvs) { await db.doTransaction(async tn => { await insert(tn, key, val); }); } }; ``` -------------------------------- ### Bulk GET Request Example Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/database/bulk-api.md Demonstrates how to retrieve multiple documents from a database using the _bulk_get endpoint. Specify document IDs and optionally revisions. ```json { "docs": [ { "id": "a", "rev": "1-23202479633c2b380f79507a776743d5" }, { "id": "b" }, { "id": "c", "rev": "1-967a00dff5e02add41819138abb3284d" } ] } ``` -------------------------------- ### Basic Attachments Info Request Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/document/common.md This is an example of an HTTP GET request to retrieve a document that includes attachment metadata. The `Accept` header specifies that JSON is expected. ```http GET /recipes/SpaghettiWithMeatballs HTTP/1.1 Accept: application/json Host: localhost:5984 ``` -------------------------------- ### Create runit Configuration Directories Source: https://github.com/apache/couchdb/blob/main/src/docs/src/install/unix.md Sets up the necessary directory structure for runit's CouchDB service configuration. ```sh sudo mkdir /etc/sv/couchdb sudo mkdir /etc/sv/couchdb/log ``` -------------------------------- ### Basic Nouveau Server Configuration Source: https://github.com/apache/couchdb/blob/main/src/docs/src/install/nouveau.md This is a sample `nouveau.yaml` file. Refer to the DropWizard documentation for a full list of configuration options. ```yaml maxIndexesOpen: 100 commitIntervalSeconds: 30 idleSeconds: 60 rootDir: target/indexes ``` -------------------------------- ### GET Nouveau Index Info Response Source: https://github.com/apache/couchdb/blob/main/src/docs/src/api/ddoc/nouveau.md Example JSON response for a successful request to the Nouveau Info API. This response includes details about the specified search index. ```json HTTP/1.1 200 OK Content-Type: application/json { "name": "_design/cookbook/ingredients", "search_index": { "num_docs": 1000, "update_seq": 5000, "disk_size": 1048576 } } ``` -------------------------------- ### Start CouchDB as CouchDB User Source: https://github.com/apache/couchdb/blob/main/INSTALL.Unix.md Start the CouchDB server as the dedicated `couchdb` user using `sudo`. This is the recommended way for the first run. ```bash sudo -i -u couchdb couchdb/bin/couchdb ```