1.7. Local (non-replicating) Documents

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.

Local documents have the following limitations:

  • Local documents are not replicated to other databases.

  • Local documents are not output by views, or the /{db}/_all_docs view.

From CouchDB 2.0, Local documents can be listed by using the /db/_local_docs endpoint.

Local documents can be used when you want to store configuration or other information for the current (local) instance of a given database.

A list of the available methods and URL paths are provided below:

Method

Path

Description

GET, POST

/db/_local_docs

Returns a list of all the non-replicated documents in the database

GET

/db/_local/id

Returns the latest revision of the non-replicated document

PUT

/db/_local/id

Inserts a new version of the non-replicated document

DELETE

/db/_local/id

Deletes the non-replicated document

COPY

/db/_local/id

Copies the non-replicated document

1.7.1. /db/_local_docs

GET /{db}/_local_docs

Returns a JSON structure of all of the local documents in a given database. The information is returned as a JSON structure containing meta information about the return structure, including a list of all local documents and basic contents, consisting the ID, revision and key. The key is the from the local document’s _id.

  • Parameters

    • db – Database name

    Request Headers

    • Accept

      • application/json

      • text/plain

    Query Parameters

    • conflicts (boolean) – Includes conflicts information in response. Ignored if include_docs isn’t true. Default is false.

    • descending (boolean) – Return the local documents in descending by key order. Default is false.

    • endkey (string) – Stop returning records when the specified key is reached. Optional.

    • end_key (string) – Alias for endkey param.

    • endkey_docid (string) – Stop returning records when the specified local document ID is reached. Optional.

    • end_key_doc_id (string) – Alias for endkey_docid param.

    • include_docs (boolean) – Include the full content of the local documents in the return. Default is false.

    • inclusive_end (boolean) – Specifies whether the specified end key should be included in the result. Default is true.

    • key (string) – Return only local documents that match the specified key. Optional.

    • keys (string) – Return only local documents that match the specified keys. Optional.

    • limit (number) – Limit the number of the returned local documents to the specified number. Optional.

    • skip (number) – Skip this number of records before starting to return the results. Default is 0.

    • startkey (string) – Return records starting with the specified key. Optional.

    • start_key (string) – Alias for startkey param.

    • startkey_docid (string) – Return records starting with the specified local document ID. Optional.

    • start_key_doc_id (string) – Alias for startkey_docid param.

    • update_seq (boolean) – Response includes an update_seq value indicating which sequence id of the underlying database the view reflects. Default is false.

    Response Headers

    • Content-Type

      • application/json

      • text/plain; charset=utf-8

    Response JSON Object

    • offset (number) – Offset where the local document list started

    • rows (array) – Array of view row objects. By default the information returned contains only the local document ID and revision.

    • total_rows (number) – Number of local documents in the database. Note that this is not the number of rows returned in the actual query.

    • update_seq (number) – Current update sequence for the database

    Status Codes

    • 200 OK – Request completed successfully

Request:

  1. GET /db/_local_docs HTTP/1.1
  2. Accept: application/json
  3. Host: localhost:5984

Response:

  1. HTTP/1.1 200 OK
  2. Cache-Control: must-revalidate
  3. Content-Type: application/json
  4. Date: Sat, 23 Dec 2017 16:22:56 GMT
  5. Server: CouchDB (Erlang/OTP)
  6. Transfer-Encoding: chunked
  7. {
  8. "offset": null,
  9. "rows": [
  10. {
  11. "id": "_local/localdoc01",
  12. "key": "_local/localdoc01",
  13. "value": {
  14. "rev": "0-1"
  15. }
  16. },
  17. {
  18. "id": "_local/localdoc02",
  19. "key": "_local/localdoc02",
  20. "value": {
  21. "rev": "0-1"
  22. }
  23. },
  24. {
  25. "id": "_local/localdoc03",
  26. "key": "_local/localdoc03",
  27. "value": {
  28. "rev": "0-1"
  29. }
  30. },
  31. {
  32. "id": "_local/localdoc04",
  33. "key": "_local/localdoc04",
  34. "value": {
  35. "rev": "0-1"
  36. }
  37. },
  38. {
  39. "id": "_local/localdoc05",
  40. "key": "_local/localdoc05",
  41. "value": {
  42. "rev": "0-1"
  43. }
  44. }
  45. ],
  46. "total_rows": null
  47. }

POST /{db}/_local_docs

POST _local_docs functionality supports identical parameters and behavior as specified in the GET /{db}/_local_docs API but allows for the query string parameters to be supplied as keys in a JSON object in the body of the POST request.

Request:

  1. POST /db/_local_docs HTTP/1.1
  2. Accept: application/json
  3. Content-Length: 70
  4. Content-Type: application/json
  5. Host: localhost:5984
  6. {
  7. "keys" : [
  8. "_local/localdoc02",
  9. "_local/localdoc05"
  10. ]
  11. }

The returned JSON is the all documents structure, but with only the selected keys in the output:

  1. {
  2. "total_rows" : null,
  3. "rows" : [
  4. {
  5. "value" : {
  6. "rev" : "0-1"
  7. },
  8. "id" : "_local/localdoc02",
  9. "key" : "_local/localdoc02"
  10. },
  11. {
  12. "value" : {
  13. "rev" : "0-1"
  14. },
  15. "id" : "_local/localdoc05",
  16. "key" : "_local/localdoc05"
  17. }
  18. ],
  19. "offset" : null
  20. }

1.7.2. /db/_local/id

GET /{db}/_local/{docid}

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 GET /{db}/{docid}.

PUT /{db}/_local/{docid}

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 PUT /{db}/{docid}.

DELETE /{db}/_local/{docid}

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 DELETE /{db}/{docid}.

COPY /{db}/_local/{docid}

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 COPY /{db}/{docid}.