Database / CouchDB Interview Questions
What data model does CouchDB use and how is a document structured?
CouchDB uses a document data model: all data is stored as discrete JSON objects grouped into databases. There is no enforced schema — documents in the same database can have entirely different fields.
Every CouchDB document has two mandatory system fields:
_id— the unique primary key. If omitted, CouchDB generates a UUID. Typed prefix conventions like"order:2024-001"co-locate related documents in the B-tree._rev— the current revision token in the format{generation}-{md5hash}. You must supply the current_revon every update or delete.
{
"_id": "order:2024-00188",
"_rev": "2-7d3a9f012b4e8c56ab1d2ef3",
"type": "order",
"customer_id": "user:42",
"items": [
{ "sku": "WIDGET-01", "qty": 3, "price": 9.99 },
{ "sku": "GADGET-07", "qty": 1, "price": 49.00 }
],
"total": 78.97,
"status": "pending",
"created_at": "2024-03-15T08:22:00Z",
"_attachments": {
"invoice.pdf": {
"content_type": "application/pdf",
"length": 48312,
"stub": true
}
}
}
Values can be any valid JSON type: strings, numbers, booleans, arrays, or nested objects. Binary data is stored as attachments under the reserved _attachments key. Special system documents — design documents (_design/) and local documents (_local/) — live in the same database namespace but are handled differently by the replication engine.
More Related questions...