hieudoanm/hieudoanm.github.io/couchdb

Claude Code and agent skill by hieudoanm/hieudoanm.github.io

Trust tier 2
  • community
LLM review pending
Source check pending

Checking that the SKILL.md file is still in the repository.

CouchDB — source-first JSON document database with HTTP API, multi-master replication, and map/reduce views.

Install

npx vskill@latest install hieudoanm/hieudoanm.github.io/couchdb

SKILL.md

The same SKILL.md was published earlier as hieudoanm/hieudoanm.github.io/couchdb.

CouchDB is a JSON document database with a pure HTTP API, built around master-master replication and an MVCC document model designed for offline-friendly, fault-tolerant applications.

1. Core Concepts

  • Documents are JSON objects stored under a unique _id with a _rev (revision) token.
  • Databases are collections of documents; views/indexes are per-database.
  • Replication synchronizes databases between nodes or clients continuously or on demand.
  • MVCC: document revisions are immutable; conflicts are resolved by application merge logic or by picking the latest valid revision.
  • Query via views, defined as map/reduce functions written in JavaScript. Live listing with _changes and filtering with _selector (Mango).

2. Access via HTTP

  • REST API: GET/PUT/POST/DELETE /db/{docid}.
  • Maintenance: GET /_all_dbs, _changes feed, _compact, _replicate.
bash
# optimistic concurrency: create, then always send _rev back on update
curl -sS -X PUT "$CB/orders" -H 'Content-Type: application/json' \
-d '{"_id":"order:1001","status":"pending","total":99.00}'
REV=$(curl -sS "$CB/orders/order:1001" | jq -r ._rev)
curl -sS -X PUT "$CB/orders/order:1001" -H 'Content-Type: application/json' \
-H "If-Match: $REV" \
-d "{\"_rev\":\"$REV\",\"status\":\"paid\",\"total\":99.00}"
bash
services:
couchdb:
image: couchdb:3.5 # pin a stable version for reproducibility
ports:
- "5984:5984"
environment:
COUCHDB_USER: admin
COUCHDB_PASSWORD: StrongPassword123!
volumes:
- couchdb_data:/opt/couchdb/data

Runnable: `examples/docker/compose/databases/documental/couchdb/docker-compose.yaml`

  • Authentication: Basic, JWT, or Cookie (session) vs. PW / Local (DB setup). Use _users DB for _design docs? (Create dedicated users.)
  • Use ETag/If-Match and _rev to implement optimistic concurrency: always send _rev on update; a 409 Conflict means a revision mismatch.
  • Bulk operations: _bulk_docs with all_or_nothing; transactions not supported — use independent documents.

3. Views and Indexes

  • Design documents (_design/*) contain view functions; they run against a snapshot of the database (B-tree) and are rebuilt lazily via the _view endpoints.
  • Map function: emit(key, value); reduce optional: sum, count, or custom.
  • For range lookups pass startkey/endkey, include_docs=true.
  • Mango (Query Server) indexes (_index) provide $eq, $gt, $regex-style selectors; create via _index endpoint.
  • Prefer views over full scan for hot paths; sparse views (only emit needed docs) reduce index size.
javascript
// sparse view: only emit for documents that actually matter to this query
function ordersByCustomer(doc) {
if (doc.type !== 'order' || !doc.customerId) return null; // no emit = not indexed
emit([doc.customerId, doc.createdAt], {
total: doc.total,
status: doc.status,
});
}
bash
# range read over the view: one customer, all their orders
curl -sS -G "$CB/orders/_design/orders/_view/by-customer" \
--data-urlencode 'group=true' \
--data-urlencode 'startkey=["cus_42"]' \
--data-urlencode 'endkey=["cus_42",{}]' \
--data-urlencode 'include_docs=true'

4. Conflicts and Replication

  • Replication is asynchronous; each node can have different revision trees.
  • Conflicts appear as _conflicts in a document; resolve by updating the base revision with merged content.
  • Replicated conflicts must be resolved client-side; design the app to tolerate eventual consistency.
  • Use filtered replication with _selector/filter functions to replicate subsets (e.g., per-user).

5. Operational Practices

  • Run at least 3 nodes; use the cluster module (Paxos-based) for automatic sharding.
  • Compact databases and views periodically: _compact and _view_cleanup release disk (tombstone overhead).
  • Monitor via _stats, _active_tasks, Prometheus (/ _metrics).
  • Store attachments either inline or in a separate blob store — attachments bloat replication and compaction.
  • Backup via replication to a separate CouchDB instance or the snapshot tooling (e.g., couchdb-dumps).

6. Common Pitfalls

  • Ignoring _rev and generating 409 conflicts — always marshal from latest revision.
  • Building views that emit for every document — this creates huge indexes and slows replication.
  • Using CouchDB as a relational DB with joins and transactions.
  • Letting attachment blobs clog the database — prefer external storage or large _attachment limits.
  • Not resolving conflicts: they silently accumulate and can cause data inconsistency.

General Rules of Thumb

  • Design for eventual consistency and conflict resolution first; CouchDB is intentionally final-less.
  • Use views for stable, well-defined queries; use Mango for ad-hoc/exploratory filtering.
  • Keep documents small and coarse-grained — one JSON document per business entity, not per field.
  • Monitor compaction and tombstone growth; schedule compaction off-peak.

Quick-Start Checklist

  • [ ] Chose your transport: HTTP API or SDK (e.g., pouchdb, couchbase SDK, nano).
  • [ ] Set up authentication (users DB, JWT/scoped users) and CORS allowances.
  • [ ] Design documents with unique _ids and a revision-merge strategy.
  • [ ] Add views/Mango indexes only for actual lookup patterns.
  • [ ] Configure replication topology (master-master, filtered) with conflict handling.
  • [ ] Plan compaction schedule and backup replication strategy.
  • [ ] Enable monitoring for replication lag, disk usage, and tombstone overhead.
  • [ ] Test offline behavior and synchronous merge paths before shipping.

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewNot runA model review is scheduled for the next rescan.

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/hieudoanm/hieudoanm.github.io/couchdb/badge)](https://verified-skill.com/skills/hieudoanm/hieudoanm.github.io/couchdb)

Something wrong with this skill or its page? Tell us.