### Start Search Service Source: https://docs.couchdb.org/en/stable/_sources/install/search.rst.txt Example command to start the search service with specified JVM options, logging configuration, and main class. ```bash java -server \ -Xmx2G \ -Dsun.net.inetaddr.ttl=30 \ -Dsun.net.inetaddr.negative.ttl=30 \ -Dlog4j.configuration=file:/path/to/log4j.properties \ -XX:OnOutOfMemoryError="kill -9 %p" \ -XX:+UseConcMarkSweepGC \ -XX:+CMSParallelRemarkEnabled \ com.cloudant.clouseau.Main \ /path/to/clouseau.ini ``` -------------------------------- ### Start CouchDB Server Source: https://docs.couchdb.org/en/stable/install/unix.html Starts the CouchDB server as the 'couchdb' user. This command should be run after initial setup and user creation. ```bash sudo -i -u couchdb /home/couchdb/bin/couchdb ``` -------------------------------- ### CouchDB Snap Configuration Example Source: https://docs.couchdb.org/en/stable/_sources/install/snap.rst.txt Example configuration stanza for CouchDB snap, specifying data directories. Ensure this matches your installation path. ```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 ``` -------------------------------- ### Basic _nouveau Query with GET Source: https://docs.couchdb.org/en/stable/_sources/ddocs/nouveau.rst.txt Example of a basic GET request to the _nouveau endpoint with query parameters. ```bash curl https://$HOST:5984/$DATABASE/_design/$DDOC/_nouveau/$INDEX_NAME? include_docs=true&q=*:*&limit=1 \ ``` -------------------------------- ### CouchDB Configuration for Snap Installation Source: https://docs.couchdb.org/en/stable/install/snap.html Example configuration stanza for CouchDB within a snap installation. Ensure `database_dir` and `view_index_dir` point to the correct writable path. ```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 ``` -------------------------------- ### Clone and Run Fauxton Development Server Source: https://docs.couchdb.org/en/stable/_sources/fauxton/install.rst.txt Set up a local development environment for Fauxton by cloning the repository and installing dependencies, then starting the development server. Requires Node.js and npm. ```bash $ git clone https://github.com/apache/couchdb-fauxton.git $ npm install && npm run dev ``` -------------------------------- ### POST /{db}/_explain Request Example Source: https://docs.couchdb.org/en/stable/api/database/find.html This example demonstrates how to use the POST /{db}/_explain endpoint to get information about the index used for a specific query. The request body contains the same parameters as the _find endpoint. ```http POST /movies/_explain HTTP/1.1 Accept: application/json Content-Type: application/json Content-Length: 168 Host: localhost:5984 { "selector": { "year": {"$gt": 2010} }, "fields": ["_id", "_rev", "year", "title"], "sort": [{"year": "asc"}], "limit": 2, "skip": 0 } ``` -------------------------------- ### GET Request to _cluster_setup Source: https://docs.couchdb.org/en/stable/_sources/api/server/common.rst.txt Retrieves the current status of the cluster setup wizard. This endpoint is useful for understanding the state of node or cluster initialization. ```http GET /_cluster_setup HTTP/1.1 Host: localhost:5984 Accept: application/json ``` -------------------------------- ### Get CouchDB Cluster Setup Status Source: https://docs.couchdb.org/en/stable/api/server/common.html Use this GET request to retrieve the current status of the node or cluster as defined by the cluster setup wizard. The `ensure_dbs_exist` query parameter can be used to specify system databases that should exist. ```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"} ``` -------------------------------- ### Start CouchDB and Log Output Source: https://docs.couchdb.org/en/stable/_sources/install/troubleshooting.rst.txt Navigate to the release directory and start CouchDB, logging its output. ```bash cd rel/couchdb bin/couchdb ``` -------------------------------- ### Proxy Authentication Request Example Source: https://docs.couchdb.org/en/stable/api/server/authn.html An example HTTP GET request to CouchDB demonstrating the use of proxy authentication headers. ```http GET /_session HTTP/1.1 Host: localhost:5984 Accept: application/json Content-Type: application/json; charset=utf-8 X-Auth-CouchDB-Roles: users,blogger X-Auth-CouchDB-UserName: foo X-Auth-CouchDB-Token: 3f0786e96b20b0102b77f1a49c041be6977cfb3bf78c41a12adc121cd9b4e68a ``` -------------------------------- ### Authorize Database Creation with Basic Auth Source: https://docs.couchdb.org/en/stable/_sources/intro/security.rst.txt Shows how to successfully create a database using correct admin credentials with basic authentication. ```bash HOST="http://anna:secret@127.0.0.1:5984" curl -X PUT $HOST/somedatabase ``` -------------------------------- ### Uninstall CouchDB Silently Without Installer File Source: https://docs.couchdb.org/en/stable/_sources/install/windows.rst.txt Use this command for a silent uninstall when the original installer file is not available. The product code (GUID) of the installed CouchDB is required. ```batch msiexec /x {4CD776E0-FADF-4831-AF56-E80E39F34CFC} /quiet /norestart ``` -------------------------------- ### Create a JSON Index with All Parameters Source: https://docs.couchdb.org/en/stable/api/database/find.html This example demonstrates creating a JSON index using all available query parameters, including partial filter selectors and partitioning options. ```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 } ``` -------------------------------- ### Start the Nouveau Server Source: https://docs.couchdb.org/en/stable/_sources/install/nouveau.rst.txt Execute this command to start the Nouveau server, providing paths to the JAR file and its configuration. ```bash java -jar /path/to/nouveau.jar server /path/to/nouveau.yaml ``` -------------------------------- ### HTTP GET Request for a Document Source: https://docs.couchdb.org/en/stable/_sources/api/document/common.rst.txt Example of an HTTP GET request to retrieve a document. Ensure the Accept header is set to application/json. ```http GET /recipes/SpaghettiWithMeatballs HTTP/1.1 Accept: application/json Host: localhost:5984 ``` -------------------------------- ### JWT Authentication Request Example Source: https://docs.couchdb.org/en/stable/api/server/authn.html Example HTTP GET request to the _session endpoint with an Authorization header containing a JWT token. ```http GET /_session HTTP/1.1 Host: localhost:5984 Accept: application/json Content-Type: application/json; charset=utf-8 Authorization: Bearer ``` -------------------------------- ### Start the Nouveau Server Source: https://docs.couchdb.org/en/stable/install/nouveau.html Execute this command to start the Nouveau server using its JAR file and configuration. ```bash java -jar /path/to/nouveau.jar server /path/to/nouveau.yaml ``` -------------------------------- ### Finish CouchDB Cluster Setup Source: https://docs.couchdb.org/en/stable/_sources/setup/cluster.rst.txt Use this command to finalize the cluster setup and add system databases. Replace `` with the actual node's address. ```bash curl -X POST -H "Content-Type: application/json" http://admin:password@:5984/_cluster_setup -d '{"action": "finish_cluster"}' ``` -------------------------------- ### GET /recipes/_design/cookbook/_nouveau_info/ingredients Request Source: https://docs.couchdb.org/en/stable/api/ddoc/nouveau.html Example GET request to retrieve information about a Nouveau search index. Ensure the Nouveau server is running and accessible. ```http GET /recipes/_design/cookbook/_nouveau_info/ingredients HTTP/1.1 Accept: application/json Host: localhost:5984 ``` -------------------------------- ### Find API Explain Request Example Source: https://docs.couchdb.org/en/stable/_sources/api/database/find.rst.txt This example demonstrates the structure of a POST request to the _explain endpoint. It includes a selector, fields to return, sorting, and limits for a query on the 'movies' database. ```http POST /movies/_explain HTTP/1.1 Accept: application/json Content-Type: application/json Content-Length: 168 Host: localhost:5984 { "selector": { "year": {"$gt": 2010} }, "fields": ["_id", "_rev", "year", "title"], "sort": [{"year": "asc"}], "limit": 2, "skip": 0 } ``` -------------------------------- ### GET Request for Database Changes Source: https://docs.couchdb.org/en/stable/_sources/api/database/changes.rst.txt Example of a GET request to the _changes endpoint to retrieve all document revisions. Use this to monitor database modifications. ```http GET /db/_changes?style=all_docs HTTP/1.1 Accept: application/json Host: localhost:5984 ``` -------------------------------- ### Query with 'endkey' and 'keys' Source: https://docs.couchdb.org/en/stable/api/ddoc/views.html This example demonstrates querying with `endkey` and `keys`. Note that `keys` is incompatible with `key`, `start_key`, and `end_key` in certain contexts. ```bash # start_key=a and end_key=a $ curl http://adm:pass@127.0.0.1:5984/db/_design/ddoc/_view/reduce'?endkey="b"&keys=\"a\"' {"rows":[{"key":null,"value":1}]} ``` ```bash $ curl http://adm:pass@127.0.0.1:5984/db/_design/ddoc/_view/reduce'?endkey="b"&keys=\"a\",\"b\"' {"error":"query_parse_error","reason":"Multi-key fetches for reduce views must use `group=true`"} ``` ```bash $ curl http://adm:pass@127.0.0.1:5984/db/_design/ddoc/_view/reduce'?endkey="b"&keys=\"a\",\"b\"&group=true' {"error":"query_parse_error","reason":"`keys` is incompatible with `key`, `start_key` and `end_key`"} ``` -------------------------------- ### GET Request for CouchDB View Source: https://docs.couchdb.org/en/stable/_sources/api/ddoc/views.rst.txt Example of a GET request to retrieve data from a CouchDB view. Ensure the 'Accept' header is set to 'application/json'. ```http GET /recipes/_design/ingredients/_view/by_name HTTP/1.1 Accept: application/json Host: localhost:5984 ``` -------------------------------- ### Creating Database With Correct Credentials Source: https://docs.couchdb.org/en/stable/intro/security.html Shows how to successfully create a database by providing correct admin credentials in the URL. The format 'username:password@' is used for basic authentication. ```bash > HOST="http://anna:secret@127.0.0.1:5984" > curl -X PUT $HOST/somedatabase {"ok":true} ``` -------------------------------- ### HTTP GET Request for Local Document Source: https://docs.couchdb.org/en/stable/_sources/replication/protocol.rst.txt This is an example of an HTTP GET request to retrieve a local document. It is used to check for existing replication information. ```http GET /source/_local/b6cef528f67aa1a8a014dd1144b10e09 HTTP/1.1 Accept: application/json Host: localhost:5984 User-Agent: CouchDB ``` -------------------------------- ### HTTP GET Response for a Document Source: https://docs.couchdb.org/en/stable/_sources/api/document/common.rst.txt Example of a successful HTTP GET response for a document. The response includes document metadata and content in JSON format. ```http HTTP/1.1 200 OK Cache-Control: must-revalidate Content-Length: 660 Content-Type: application/json Date: Tue, 13 Aug 2013 21:35:37 GMT ETag: "1-917fa2381192822767f010b95b45325b" Server: CouchDB (Erlang/OTP) { "_id": "SpaghettiWithMeatballs", "_rev": "1-917fa2381192822767f010b95b45325b", "description": "An Italian-American dish that usually consists of spaghetti, tomato sauce and meatballs.", "ingredients": [ "spaghetti", "tomato sauce", "meatballs" ], "name": "Spaghetti with meatballs" } ``` -------------------------------- ### GET /{db}/_revs_limit - Response Example Source: https://docs.couchdb.org/en/stable/_sources/api/database/misc.rst.txt A successful GET request to _revs_limit returns the current revision limit as a plain integer in the response body. ```http HTTP/1.1 200 OK Cache-Control: must-revalidate Content-Length: 5 Content-Type: application/json Date: Mon, 12 Aug 2013 17:27:30 GMT Server: CouchDB (Erlang/OTP) 1000 ``` -------------------------------- ### Create Design Document for Global Queries Source: https://docs.couchdb.org/en/stable/partitioned-dbs/index.html This example shows how to create a design document for global queries in a partitioned database. Set `"partitioned": false` in the options to enable global queries. ```json { "_id": "_design/all_sensors", "options": { "partitioned": false }, "views": { "by_field": { "map": "function(doc) { ... }" } } } ``` -------------------------------- ### Enable Cluster on Node (API) Source: https://docs.couchdb.org/en/stable/_sources/setup/cluster.rst.txt Initializes a node for cluster setup using the _cluster_setup API. This command should be run on each node. ```bash curl -X POST -H "Content-Type: application/json" http://admin:password@127.0.0.1:5984/_cluster_setup -d '{"action": "enable_cluster", "bind_address":"0.0.0.0", "username": "admin", "password":"password", "node_count":"3"}' ``` -------------------------------- ### Finish Cluster Setup Source: https://docs.couchdb.org/en/stable/_sources/setup/cluster.rst.txt Command to finalize the cluster setup and add system databases. ```APIDOC ## POST /_cluster_setup ### Description Completes the cluster setup process. ### Method POST ### Endpoint `http://admin:password@:5984/_cluster_setup` ### Parameters #### Request Body - **action** (string) - Required - The action to perform, should be `"finish_cluster"`. ``` -------------------------------- ### Get Cluster Setup Status Source: https://docs.couchdb.org/en/stable/api/server/common.html Retrieves the current state of the node or cluster as managed by the cluster setup wizard. It can optionally ensure specific 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 ### 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`. ### Response Example ```json { "state": "cluster_enabled" } ``` ``` -------------------------------- ### Cluster Setup Source: https://docs.couchdb.org/en/stable/http-routingtable.html Manages the cluster setup wizard status and configuration. ```APIDOC ## GET /_cluster_setup ### Description Return the status of the cluster setup wizard. ### Method GET ### Endpoint /_cluster_setup ``` ```APIDOC ## POST /_cluster_setup ### Description Sets up a node as a single node or as part of a cluster. ### Method POST ### Endpoint /_cluster_setup ``` -------------------------------- ### Get Cluster Setup Status Source: https://docs.couchdb.org/en/stable/_sources/api/server/common.rst.txt Retrieves the current cluster setup status of the node. This endpoint is useful for understanding the current state of the node's configuration. ```APIDOC ## GET /_cluster_setup ### Description Retrieves the current cluster setup status of the node. ### Method GET ### Endpoint /_cluster_setup ### Response #### Success Response (200) - **state** (string) - The current state of the cluster setup (e.g., "cluster_enabled", "single_node_disabled"). ### Response Example ```json { "state": "cluster_enabled" } ``` ``` -------------------------------- ### QuickJS Scanner Log Output - Start and Completion Source: https://docs.couchdb.org/en/stable/best-practices/jsdevel.html Example log messages indicating the start and completion of a QuickJS scanner session. The format includes a session ID. ```log couch_quickjs_scanner_plugin s:1725559802-c615220453e6 starting ... couch_quickjs_scanner_plugin s:1725559802-c615220453e6 completed ``` -------------------------------- ### JWT Keys Configuration Example Source: https://docs.couchdb.org/en/stable/_sources/api/server/authn.rst.txt Example INI configuration for setting up JWT keys, including symmetric and asymmetric key examples. ```ini ; [jwt_keys] ; Configure at least one key here if using the JWT auth handler. ; If your JWT tokens do not include a "kid" attribute, use "_default" ; as the config key, otherwise use the kid as the config key. ; Examples ; hmac:_default = aGVsbG8= ; hmac:foo = aGVsbG8= ; The config values can represent symmetric and asymmetric keys. ; For symmetric keys, the value is base64 encoded; ; hmac:_default = aGVsbG8= # base64-encoded form of "hello" ; For asymmetric keys, the value is the PEM encoding of the public ``` -------------------------------- ### Example: GET /recipes without Accept header Source: https://docs.couchdb.org/en/stable/api/basics.html Demonstrates a GET request to the /recipes endpoint without an explicit Accept header, showing the default response headers. ```APIDOC ## GET /recipes (without Accept header) ### Request Example ```http GET /recipes HTTP/1.1 Host: couchdb:5984 Accept: */* ``` ### 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 ``` ``` -------------------------------- ### Install CouchDB using pkg Source: https://docs.couchdb.org/en/stable/_sources/install/freebsd.rst.txt Use this command to install CouchDB from pre-built binary packages. ```bash pkg install couchdb3 ``` -------------------------------- ### Initialize Response with Start in Erlang Source: https://docs.couchdb.org/en/stable/_sources/query-server/erlang.rst.txt Use the Start function to initialize the response object, allowing you to set the response code and headers before sending the body. This example demonstrates a redirect. ```erlang fun(Head, {Req}) -> Start({[{<<"code">>, 302}, {<<"headers">>, {[ {<<"Location">>, << ``` ```erlang http://couchdb.apache.org">>}] }} ]}), "Relax!" end. ``` -------------------------------- ### GET Request for Show Function (No Document) Source: https://docs.couchdb.org/en/stable/api/ddoc/render.html Example GET request to a CouchDB show function endpoint when no specific document is targeted. This applies the show function to a null document. ```http GET /recipes/_design/recipe/_show/description HTTP/1.1 Accept: application/json Host: localhost:5984 ``` -------------------------------- ### Create a Partitioned Database Source: https://docs.couchdb.org/en/stable/partitioned-dbs/index.html Use a PUT request with the `partitioned=true` query parameter to create a new partitioned database. This is the initial step for enabling partitioning. ```shell curl -X PUT 'http://adm:pass@127.0.0.1:5984/my_new_db?partitioned=true' {"ok":true} ``` -------------------------------- ### GET /{db}/_revs_limit - Request Example Source: https://docs.couchdb.org/en/stable/_sources/api/database/misc.rst.txt Send a GET request to the _revs_limit endpoint to retrieve the current setting for the maximum number of historical revisions stored per document in a database. ```http GET /db/_revs_limit HTTP/1.1 Accept: application/json Host: localhost:5984 ``` -------------------------------- ### POST /{db}/_explain Response Example Source: https://docs.couchdb.org/en/stable/api/database/find.html This is an example of a successful response from the POST /{db}/_explain endpoint. It details the index selected, the query parameters used, and other relevant information about the query execution plan. ```json HTTP/1.1 200 OK Cache-Control: must-revalidate Content-Type: application/json Date: Thu, 01 Sep 2016 15:41:53 GMT Server: CouchDB (Erlang OTP) Transfer-Encoding: chunked { "dbname": "movies", "index": { "ddoc": "_design/0d61d9177426b1e2aa8d0fe732ec6e506f5d443c", "name": "0d61d9177426b1e2aa8d0fe732ec6e506f5d443c", "type": "json", "partitioned": false, "def": { "fields": [ { "year": "asc" } ] } }, "partitioned": false, "selector": { "year": { "$gt": 2010 } }, "opts": { "use_index": [], "bookmark": "nil", "limit": 2, "skip": 0, "sort": {}, "fields": [ "_id", "_rev", "year", "title" ], "partition": "", "r": 1, "conflicts": false, "stale": false, "update": true, "stable": false, "execution_stats": false, "allow_fallback": true }, "limit": 2, "skip": 0, "fields": [ "_id", "_rev", "year", "title" ], "mrargs": { "include_docs": true, "view_type": "map", "reduce": false, "partition": null, "start_key": [ 2010 ], "end_key": [ "" ], "direction": "fwd", "stable": false, "update": true, "conflicts": "undefined" }, "covering": false, "index_candidates": [ { "index": { "ddoc": null, "name": "_all_docs", "type": "special", "def": { "fields": [ { "_id": "asc" } ] } }, "analysis": { "usable": true, "reasons": [ { "name": "unfavored_type" } ], "ranking": 1, "covering": null } } ], "selector_hints": [ { "type": "json", "indexable_fields": [ "year" ], "unindexable_fields": [] } ] } ``` -------------------------------- ### JWT Authentication Request Source: https://docs.couchdb.org/en/stable/api/server/authn.html Example of a GET request to the _session endpoint with a JWT token for authentication. ```APIDOC ## GET /_session ### Description Authenticates a user using a JWT token provided in the Authorization header. ### Method GET ### Endpoint /_session ### Request Headers - **Authorization** (string) - Required - Bearer token with the JWT. ### Request Example ```http GET /_session HTTP/1.1 Host: localhost:5984 Accept: application/json Content-Type: application/json; charset=utf-8 Authorization: Bearer ``` ### Response #### Success Response (200) - **ok** (boolean) - Indicates if the request was successful. - **userCtx** (object) - Contains user context information. - **name** (string) - The authenticated user's name. - **roles** (array) - A list of roles assigned to the user. #### Response Example ```json { "info": { "authenticated": "jwt", "authentication_db": "_users", "authentication_handlers": [ "cookie", "proxy", "default" ] }, "ok": true, "userCtx": { "name": "foo", "roles": [ "users", "blogger" ] } } ``` ``` -------------------------------- ### Install runit Package Source: https://docs.couchdb.org/en/stable/_sources/install/unix.rst.txt Install the runit service supervision package using apt-get. ```bash sudo apt-get install runit ``` -------------------------------- ### Migrate Old Compaction Daemon Configuration Source: https://docs.couchdb.org/en/stable/maintenance/compaction.html This example shows the configuration format for the older CouchDB compaction daemon. Many settings can be ported to the new system, with differences in how fragmentation thresholds and window behaviors are handled. ```ini [compaction_daemon] min_file_size = 131072 check_interval = 3600 snooze_period_ms = 3000 [compactions] mydb = [{db_fragmentation, "70%"}, {view_fragmentation, "60%"}, {parallel_view_compaction, true}] _default = [{db_fragmentation, "50%"}, {view_fragmentation, "55%"}, {from, "20:00"}, {to, "06:00"}, {strict_window, true}] ``` -------------------------------- ### Cluster Setup API Source: https://docs.couchdb.org/en/stable/api/server/common.html The _cluster_setup endpoint is used for managing cluster setup operations in CouchDB. It handles requests related to cluster configuration and management. Refer to the external documentation for detailed examples. ```APIDOC ## GET /_cluster_setup ### Description Retrieves the current cluster setup status. ### Method GET ### Endpoint /_cluster_setup ### Response #### Success Response (200) - **state** (string) - The current state of the cluster setup. - **error** (string) - An error message if the setup failed. ## POST /_cluster_setup ### Description Initiates or continues the cluster setup process. ### Method POST ### Endpoint /_cluster_setup ### Request Body - **action** (string) - The action to perform (e.g., 'finish_cluster', 'join_cluster'). - **node_name** (string) - The name of the node. - **node_cookie** (string) - A cookie for node authentication. - **host** (string) - The hostname of the node to join. - **port** (integer) - The port of the node to join. - **username** (string) - The username for authentication. - **password** (string) - The password for authentication. ### Response #### Success Response (200) - **status** (string) - The status of the operation. ### Error Handling - **401 Unauthorized** – Unauthorized request to a protected API. - **403 Forbidden** – Insufficient permissions / Too many requests with invalid credentials. ``` -------------------------------- ### GET Request for Changes Feed (Normal Feed) Source: https://docs.couchdb.org/en/stable/_sources/replication/protocol.rst.txt This is an example of a GET request to the _changes endpoint using the 'normal' feed style. It includes parameters for including all revision leaves and a heartbeat interval. ```http GET /source/_changes?feed=normal&style=all_docs&heartbeat=10000 HTTP/1.1 Accept: application/json Host: localhost:5984 User-Agent: CouchDB ``` -------------------------------- ### Find API Explain Response Example Source: https://docs.couchdb.org/en/stable/_sources/api/database/find.rst.txt This example shows a successful response from the _explain endpoint. It details the database, the selected index, query options, and candidate indexes with their analysis, including selector hints. ```json HTTP/1.1 200 OK Cache-Control: must-revalidate Content-Type: application/json Date: Thu, 01 Sep 2016 15:41:53 GMT Server: CouchDB (Erlang OTP) Transfer-Encoding: chunked { "dbname": "movies", "index": { "ddoc": "_design/0d61d9177426b1e2aa8d0fe732ec6e506f5d443c", "name": "0d61d9177426b1e2aa8d0fe732ec6e506f5d443c", "type": "json", "partitioned": false, "def": { "fields": [ { "year": "asc" } ] } }, "partitioned": false, "selector": { "year": { "$gt": 2010 } }, "opts": { "use_index": [], "bookmark": "nil", "limit": 2, "skip": 0, "sort": {}, "fields": [ "_id", "_rev", "year", "title" ], "partition": "", "r": 1, "conflicts": false, "stale": false, "update": true, "stable": false, "execution_stats": false, "allow_fallback": true }, "limit": 2, "skip": 0, "fields": [ "_id", "_rev", "year", "title" ], "mrargs": { "include_docs": true, "view_type": "map", "reduce": false, "partition": null, "start_key": [ 2010 ], "end_key": [ "" ], "direction": "fwd", "stable": false, "update": true, "conflicts": "undefined" }, "covering": false, "index_candidates": [ { "index": { "ddoc": null, "name": "_all_docs", "type": "special", "def": { "fields": [ { "_id": "asc" } ] } }, "analysis": { "usable": true, "reasons": [ { "name": "unfavored_type" } ], "ranking": 1, "covering": null } } ], "selector_hints": [ { "type": "json", "indexable_fields": [ "year" ], "unindexable_fields": [] } ] } ``` -------------------------------- ### GET Request for Show Function (Specific Document) Source: https://docs.couchdb.org/en/stable/api/ddoc/render.html Example GET request to a CouchDB show function endpoint, targeting a specific document by its ID. This applies the show function to the specified document. ```http GET /recipes/_design/recipe/_show/description/SpaghettiWithMeatballs HTTP/1.1 Accept: application/json Host: localhost:5984 ``` -------------------------------- ### Create Database with Placement Source: https://docs.couchdb.org/en/stable/_sources/cluster/sharding.rst.txt Create a new database with specific shard placement rules by appending a query parameter to the PUT request. ```bash curl -X PUT $COUCH_URL:5984/{db}?placement={zone} ``` -------------------------------- ### Verify Cluster Setup Source: https://docs.couchdb.org/en/stable/_sources/setup/cluster.rst.txt Command to verify the current state of the cluster setup. ```APIDOC ## GET /_cluster_setup ### Description Verifies the current state of the cluster setup. ### Method GET ### Endpoint `http://admin:password@:5984/_cluster_setup` ### Response #### Success Response (200) - **state** (string) - The current state of the cluster setup, e.g., `"cluster_finished"`. ``` -------------------------------- ### HTTP Request for Cross-Design List Function Source: https://docs.couchdb.org/en/stable/_sources/api/ddoc/render.rst.txt An example HTTP GET request to execute a list function from one design document against a view in another. This example queries for 'spaghetti' using a key. ```http GET /recipes/_design/ingredient/_list/ingredients/recipe/by_ingredient?key="spaghetti" HTTP/1.1 Accept: text/plain Host: localhost:5984 ``` -------------------------------- ### HTTP GET Request for Show Function (Null Document) Source: https://docs.couchdb.org/en/stable/_sources/api/ddoc/render.rst.txt Example of an HTTP GET request to execute a show function against a null document. This is useful for generating output without a specific document context. ```http GET /recipes/_design/recipe/_show/description HTTP/1.1 Accept: application/json Host: localhost:5984 ``` -------------------------------- ### Create a document with a view Source: https://docs.couchdb.org/en/stable/api/ddoc/views.html This example demonstrates creating a document with a map/reduce view using `curl`. ```bash $ curl -X POST http://adm:pass@127.0.0.1:5984/db \ -H 'Content-Type: application/json' \ -d '{"docs":[{"_id":"a","key":"a","value":1},{"_id":"b","key":"b","value":2},{"_id":"c","key":"c","value":3}]}' $ curl -X POST http://adm:pass@127.0.0.1:5984/db \ -H 'Content-Type: application/json' \ -d '{"_id":"_design/ddoc","views":{"reduce":{"map":"function(doc) { emit(doc.key, doc.value) }","reduce":"_sum"}}}' ``` -------------------------------- ### Verify CouchDB Cluster Installation Source: https://docs.couchdb.org/en/stable/_sources/setup/cluster.rst.txt Check if the cluster setup has been successfully completed by querying the `_cluster_setup` endpoint. ```bash curl http://admin:password@:5984/_cluster_setup ``` -------------------------------- ### Install CouchDB from Ports Collection Source: https://docs.couchdb.org/en/stable/install/freebsd.html Install CouchDB by building from the Ports Collection. Navigate to the ports directory and run 'make install clean'. ```bash cd /usr/ports/databases/couchdb3 make install clean ``` -------------------------------- ### Request with JSON Accept Header Source: https://docs.couchdb.org/en/stable/api/basics.html Example of a GET request explicitly specifying `application/json` in the Accept header. ```http GET /recipes HTTP/1.1 Host: couchdb:5984 Accept: application/json ``` -------------------------------- ### Enable CouchDB service with runit Source: https://docs.couchdb.org/en/stable/_sources/install/unix.rst.txt Creates a symbolic link to enable runit to discover and start the CouchDB service. ```sh sudo ln -s /etc/sv/couchdb/ /etc/service/couchdb ``` -------------------------------- ### Install CouchDB Snap Source: https://docs.couchdb.org/en/stable/install/snap.html Installs the CouchDB snap package. Ensure snapd is installed first. ```bash $ sudo snap install couchdb ``` -------------------------------- ### HTTP GET Request for Scheduler Document Source: https://docs.couchdb.org/en/stable/_sources/api/server/common.rst.txt This snippet shows an example HTTP GET request to retrieve a specific replication document from the _scheduler/docs endpoint. Ensure the Host and port are correctly set for your CouchDB instance. ```http GET /_scheduler/docs/other/_replicator/cdyno-0000001-0000002 HTTP/1.1 Accept: application/json Host: localhost:5984 ``` -------------------------------- ### Start CouchDB Service Ad-Hoc Source: https://docs.couchdb.org/en/stable/_sources/install/freebsd.rst.txt If the service is not yet enabled in rc.conf, use 'onestart' to start it up ad-hoc. ```bash onestart ``` -------------------------------- ### Create and Populate Database Source: https://docs.couchdb.org/en/stable/_sources/cluster/sharding.rst.txt Use these bash commands to create a new database and add documents to it, which will then be sharded. ```bash $ curl -X PUT $COUCH_URL:5984/mydb {"ok":true} $ curl -X PUT $COUCH_URL:5984/mydb/joan -d '{"loves":"cats"}' {"ok":true,"id":"joan","rev":"1-cc240d66a894a7ee7ad3160e69f9051f"} $ curl -X PUT $COUCH_URL:5984/mydb/robert -d '{"loves":"dogs"}' {"ok":true,"id":"robert","rev":"1-4032b428c7574a85bc04f1f271be446e"} ```