Questions tagged [couchdb]

Apache CouchDB is a document-oriented database that can be queried and indexed in a MapReduce fashion. It exposes a pure restful API, making interaction possible from any language with the ability to send HTTP requests. This also allows "Futon", the administration interface, to work completely in the browser. It also offers incremental replication with bi-directional conflict detection and resolution.

(all below was copied directly from CouchDB's current wiki)

Introduction

Apache CouchDB is a scalable, fault-tolerant, and schema-free document-oriented database written in Erlang. It's used in large and small organizations for a variety of applications where a traditional SQL database isn't the best solution for the problem at hand. Among other features, it provides:

  • A RESTful HTTP/JSON API accessible from many programming libraries and tools
  • Futon, a browser based GUI and management tool
  • Incremental and flexible replication with conflict management
  • Incremental Map/Reduce queries written in any language (JavaScript support built-in)
  • Excellent data integrity/reliability
  • Native support for BLOBs (Binary Large Objects)
  • Easy installation on many platforms, from servers to mobile devices
  • A strong and active community
  • Good documentation in the form of Books, Presentations, Blog Posts, Wikis, and more

Because the data stored in CouchDB is a JSON document(s), the structure of the data, or document(s), can change dynamically. This feature greatly simplifies the maintenance and development of the database, especially over time when the data and its use evolve. Additionally, CouchDB doesn't rely on SQL JOINS to merge related data. This is often confusing for some users of traditional SQL databases, but is generally a non-issue once CouchDB users become familiar its powerful Map/Reduce framework.

One of CouchDB's most powerful features is its replication framework. This replication framework provides a comprehensive set of features:

  • Master → Slave replication
  • Master ↔ Master replication
  • Filtered Replication
  • Incremental replication with bi-directional conflict detection/resolution

These replication features can be used in combination to create powerful solutions to many problems in the IT industry, like reliability, and scalability. In addition to the fantastic replication features, CouchDB's reliability and scalability is further enhanced by being implemented in the Erlang programming language. Erlang has built-in support for concurrency, distribution, fault tolerance, and has been used for years to build reliable systems in the telecommunications industry. By design, the Erlang language and runtime are able to take advantage of newer hardware with multiple CPU cores. When you look at all of the great characteristics of Erlang, it becomes clear why CouchDB uses it for its foundation.

What it is Not

To better understand what CouchDB is, it may be helpful to understand a few things that CouchDB isn't.

  • A relational database. These differences are articulated above in the Meet CouchDB section, and other portions of this Wiki.
  • A replacement for all databases. When developing and designing a good information system you should select the best tool for the job. While CouchDB can be used in a wide variety of application types, including financial, you may find that a relational database, or other data store, is a better fit for your problem. If you are new to CouchDB, and aren't sure if it's a good fit for your data management problem, please ask others on the mailing list, and the #couchdb IRC channel for advice.
  • An object-oriented database. While CouchDB stores JSON objects, it isn't meant to function as a seamless persistence layer for an OO programming language.

Key Characteristics

Let's review some of the basic elements of CouchDB.

Documents

A CouchDB document is a JSON object that consists of named fields. Field values may be strings, numbers, dates, or even ordered lists and associative maps. An example of a document would be a blog post:

{
    "Subject": "I like Plankton"
    "Author": "Rusty"
    "PostedDate": "5/23/2006"
    "Tags": ["plankton", "baseball", "decisions"]
    "Body": "I decided today that I don't like baseball. I like plankton."
}

In the above example document, Subject is a field that contains a single string value "I like plankton". Tags is a field containing the list of values "plankton", "baseball", and "decisions".

A CouchDB database is a flat collection of these documents. Each document is identified by a unique ID.

Views

To address this problem of adding structure back to semi-structured data, CouchDB integrates a view model using JavaScript for description. Views are the method of aggregating and reporting on the documents in a database, and are built on-demand to aggregate, join and report on database documents. Views are built dynamically and don’t affect the underlying document; you can have as many different view representations of the same data as you like.

Schema-Free

Unlike SQL databases which are designed to store and report on highly structured, interrelated data, CouchDB is designed to store and report on large amounts of semi-structured, document oriented data. CouchDB greatly simplifies the development of document oriented applications, which make up the bulk of collaborative web applications.

In an SQL database, as needs evolve the schema and storage of the existing data must be updated. This often causes problems as new needs arise that simply weren't anticipated in the initial database designs, and makes distributed "upgrades" a problem for every host that needs to go through a schema update.

With CouchDB, no schema is enforced, so new document types with new meaning can be safely added alongside the old. The view engine, using JavaScript, is designed to easily handle new document types and disparate but similar documents.

Distributed

CouchDB is a peer based distributed database system. Any number of CouchDB hosts (servers and offline-clients) can have independent "replica copies" of the same database, where applications have full database interactivity (query, add, edit, delete). When back online or on a schedule, database changes are replicated bi-directionally.

CouchDB has built-in conflict detection and management and the replication process is incremental and fast, copying only documents and individual fields changed since the previous replication. Most applications require no special planning to take advantage of distributed updates and replication.

Unlike cumbersome attempts to bolt distributed features on top of the same legacy models and databases, it is the result of careful ground-up design, engineering and integration. The document, view, security and replication models, the special purpose query language, the efficient and robust disk layout are all carefully integrated for a reliable and efficient system.

Useful links


Books


Related tags :

6131 questions
33
votes
7 answers

Convert HTML to plain text in JS without browser environment

I have a CouchDB view map function that generates an abstract of a stored HTML document (first x characters of text). Unfortunately I have no browser environment to convert HTML to plain text. Currently I use this multi-stage…
user187676
31
votes
3 answers

How do I change the database file location for couchdb?

I've got couchdb installed from a package manager (Ubuntu, 10.04), but the partition where couchdb is installed is not especially big (~5GB). I'd like to move the database files to a bigger partition I set aside for the db, but I can't seem to find…
FTWynn
  • 1,349
  • 2
  • 11
  • 11
31
votes
2 answers

CouchDB Document Update Handlers (in-place updates)

http://wiki.apache.org/couchdb/Document_Update_Handlers CouchDB ( 0.10 and above ) supports in-place updates now. I'm having trouble understanding how it works. I tried to use the example provided but I couldn't get it to work. Can someone provide…
Jason
  • 311
  • 1
  • 3
  • 3
31
votes
6 answers

What is best practice when creating document IDs in couchdb?

We all know that for relational databases it is best practice to use numerical IDs for the primary key. In couchdb the default ID that is generated is a UUID. Is it best to stick with the default, or use an easily memorable identifier that will be…
andyuk
  • 38,118
  • 16
  • 52
  • 52
30
votes
1 answer

Which database out of CouchDB, MongoDB and Redis is good for starting out with Node.js?

I'm getting more into Node.js and am enjoying it. I'm moving more into web application development. I have wrapped my head around Node.js and currently using Backbone for the front end. I'm making a few applications that uses Backbone to communicate…
littlejim84
  • 9,071
  • 15
  • 54
  • 77
30
votes
3 answers

Get all design documents in CouchDB

How can I get a list of all design documents in CouchDB? Using a http query, not futon.
user89021
  • 14,784
  • 16
  • 53
  • 65
29
votes
8 answers

What's the best way to store and yet still index encrypted customer data?

I'm building an application that needs to store sensitive information, which means the data is encrypted on my database so that a hacker/employee with access to the database cannot decipher the sensitive data. However, it still needs to be…
dan
  • 43,914
  • 47
  • 153
  • 254
29
votes
3 answers

Retrieve just deleted document

I deleted a document but I can still see it in _changes, so I can see last valid _rev, which is deleted, so get doc with id and last revision just returns: { "_id":"25efa4ec8489d8b89b34c5cad6000059", "_rev":"3-a982bd6dccce8f405433f8453ab86880", …
avalez
  • 1,217
  • 1
  • 10
  • 15
28
votes
5 answers

What's the best way to store datetimes (timestamps) in CouchDB?

I'm thinking that UTC time strings like 2011-01-26 21:41:09 +0000 might be okay since they sort correctly if they are used in a view key, but storing the time zone (e.g. 2011-01-26 16:41:09 -0500) would make the document more readable. Converting…
dan
  • 43,914
  • 47
  • 153
  • 254
28
votes
7 answers

Anatomy of a Distributed System in PHP

I've a problem which is giving me some hard time trying to figure it out the ideal solution and, to better explain it, I'm going to expose my scenario here. I've a server that will receive orders from several clients. Each client will submit a…
Alix Axel
  • 151,645
  • 95
  • 393
  • 500
27
votes
7 answers

Databases using JSON as storage/transport format

How many database systems there are that use JSON for storage or transport? I know of: CouchDB MongoDB DBSlayer I remember I saw yet another vendor in a SO user's profile. That systems was using what they called binary JSON, but I can't remember…
Ionuț G. Stan
  • 176,118
  • 18
  • 189
  • 202
27
votes
6 answers

Approaches to generate auto-incrementing numeric ids in CouchDB

Since CouchDB does not have support for SQL alike AUTO_INCREMENT what would be your approach to generate sequential unique numeric ids for your documents? I am using numeric ids for: User-friendly IDs (e.g. TASK-123, RQ-001, etc.) Integration with…
aku
  • 122,288
  • 32
  • 173
  • 203
27
votes
3 answers

CouchDB Authorization on a Per-Database Basis

I'm working on an application supported by CouchDB. Essentially, I want to create a database for each individual user of my app. To accomplish this, the admin user will create the database, but going forward, the user will need to access their…
Aaron Vegh
  • 5,217
  • 7
  • 48
  • 75
27
votes
4 answers

Are there any tools for schema migration for NoSQL databases?

I'm looking a way to automate schema migration for such databases like MongoDB or CouchDB. Preferably, this instument should be written in python, but any other language is ok.
Alexander Artemenko
  • 21,378
  • 8
  • 39
  • 36
27
votes
4 answers

Unique constraints in couchdb

Are there any techniques/proposals to enforce unique constraints? Yes, we can create key that's unique, but we cannot change key and keys and also this approach is not suitable for complicated validation (separate unique login, separate unique…
Sam
  • 428
  • 1
  • 4
  • 11