CouchDB is an open-source, document-oriented NoSQL database developed by the Apache Software Foundation. CouchDB stores data as JSON documents containing key-value pairs, lists, and maps.
- Flexible Document Model: Stores data in schema-less JSON documents.
- Powerful Querying: Supports data filtering, mapping, and querying.
- RESTful API: Uses an HTTP-based REST API for easy database communication.
- Simple HTTP Methods: Supports standard methods like GET, PUT, and DELETE for CRUD operations.
CouchDB Data Model
- In CouchDB each database is a collection of independent documents which makes the outermost data structure/container of it.
- Each document maintains its own data and self-contained schema.
- To merge the differences occurred while the databases were disconnected, Document metadata contains revision information.
- To avoid the need to lock the database field during writes, it implements multi version concurrency control.
Simple CouchDB Document Structure
{
"_id": "101",
"name": "John Doe",
"age": 25,
"email": "john@example.com",
"city": "Mumbai"
}
- _id: Unique identifier for the document.
- Fields: Store data as key-value pairs (e.g., name, age, email, city).
- JSON Format: Documents are stored in JSON format.
- Flexible Schema: Different documents can have different fields.
Advantages
- Schema-less Database: Stores JSON documents without requiring a fixed schema.
- Easy Replication: Supports master-master replication and data synchronization across multiple servers.
- RESTful API: Uses HTTP/HTTPS, making it easy to integrate with web applications.
- Offline-First Support: Allows applications to work offline and synchronize data when connectivity is restored.
Limitations
- No Native Joins: Does not support SQL-style joins between documents.
- Limited Querying: Complex queries are harder compared to relational databases.
- Eventual Consistency: Replicated data may not be immediately consistent across all nodes.
- Not Suitable for Highly Relational Data: Performs poorly for applications with many interconnected relationships