Apache CouchDB Tutorial
  • couchdb - Tutorial
  • - Css
  • - W3css
  • couchdb - Useful Resources
  • Couchdb - Ebook Download


  • Apache CouchDB


    Apache CouchDB is an open-source document-oriented NoSQL database, implemented in Erlang.

    CouchDB uses multiple formats and protocols to store, transfer, and process its data, it uses JSON to store data, JavaScript as its query language using MapReduce, and HTTP for an API.

    CouchDB was first released in 2005 and later became an Apache Software Foundation project in 2008.

    Unlike a relational database, a CouchDB database does not store data and relationships in tables. Instead, each database is a collection of independent documents. Each document maintains its own data and self-contained schema. An application may access multiple databases, such as one stored on a user's mobile phone and another on a server. Document metadata contains revision information, making it possible to merge any differences that may have occurred while the databases were disconnected.

    CouchDB implements a form of multiversion concurrency control MVCC so it does not lock the database file during writes. Conflicts are left to the application to resolve. Resolving a conflict generally involves first merging data into one of the documents, then deleting the stale one.

    Other features include document-level ACID semantics with eventual consistency, incremental MapReduce, and incremental replication. One of CouchDB's distinguishing features is multi-master replication, which allows it to scale across machines to build high-performance systems. A built-in Web application called Fauxton formerly Futon helps with administration.

    History


    Couch is an acronym for cluster of unreliable commodity hardware. The CouchDB project was created in April 2005 by Damien Katz, a former Lotus Notes developer at IBM. He self-funded the project for almost two years and released it as an open-source project under the GNU General Public License.

    In February 2008, it became an Apache Incubator project and was offered under the Apache License instead. A few months after, it graduated to a top-level project. This led to the first stable version being released in July 2010.

    In early 2012, Katz left the project to focus on Couchbase Server.

    Since Katz's departure, the Apache CouchDB project has continued, releasing 1.2 in April 2012 and 1.3 in April 2013. In July 2013, the CouchDB community merged the codebase for BigCouch, Cloudant's clustered version of CouchDB, into the Apache project. The BigCouch clustering framework is included in the current release of Apache CouchDB.

    Native clustering is supported at version 2.0.0. And the new Mango Query Server provides a simple JSON-based way to perform CouchDB queries without JavaScript or MapReduce.

    Main features


    CouchDB also offers a built-in administration interface accessible via Web called Futon.

    Use cases and production deployments


    Replication and synchronization capabilities of CouchDB make it ideal for using it in mobile devices, where network connection is not guaranteed, and the application must keep on working offline.

    CouchDB is well suited for applications with accumulating, occasionally changing data, on which pre-defined queries are to be run and where versioning is important CRM, CMS systems, by example. Master-master replication is an especially interesting feature, allowing easy multi-site deployments.

    Users of CouchDB include:

    Data manipulation: documents and views


    CouchDB manages a collection of JSON documents. The documents are organised via views. Views are defined with aggregate functions and filters are computed in parallel, much like MapReduce.

    Views are generally stored in the database and their indexes updated continuously. CouchDB supports a view system using external socket servers and a JSON-based protocol. As a consequence, view servers have been developed in a variety of languages JavaScript is the default, but there are also PHP, Ruby, Python and Erlang.

    Applications interact with CouchDB via HTTP. The following demonstrates a few examples using cURL, a command-line utility. These examples assume that CouchDB is running on localhost 127.0.0.1 on port 5984.

    curl http://127.0.0.1:5984/
    
    {
      "couchdb": "Welcome",
      "version":"1.1.0"
    }
    
    curl -X PUT http://127.0.0.1:5984/wiki
    
    {"ok": true}
    
    curl -X PUT http://127.0.0.1:5984/wiki
    
    {
      "error":"file_exists",
      "reason":"The database could not be created, the file already exists."
    }
    
    curl http://127.0.0.1:5984/wiki
    
    {
      "db_name": "wiki",
      "doc_count": 0,
      "doc_del_count": 0,
      "update_seq": 0,
      "purge_seq": 0,
      "compact_running": false,
      "disk_size": 79,
      "instance_start_time": "1272453873691070",
      "disk_format_version": 5
    }
    
    curl -X DELETE http://127.0.0.1:5984/wiki
    
    {"ok": true}
    
    curl -X POST -H "Content-Type: application/json" --data \
    '{ "text" : "Wikipedia on CouchDB", "rating": 5 }' \
    http://127.0.0.1:5984/wiki
    
    {
      "ok": true,
      "id": "123BAC",
      "rev": "946B7D1C"
    }
    

    PouchDB


    The PouchDB is a Javascript implementation of CouchDB which is API compatible with it. So you can use CouchDB on the server side and Pouch in the application itself and once the application comes online you can sync both. This is especially useful for progressive web applications who rely on an offline first approach.

    Open source components


    CouchDB includes a number of other open source projects as part of its default package.