What Will I Learn?
- Advantages of CouchDB
- Companies using CouchDB
- Basic Terminology
- Installing CouchDB on Windows, Mac and Linux.
- CouchDB Commands
Requirements
- Basic data base
- Basic javascript
Difficulty
- Basic
Introduction
Nosql DBMS are much like sql DBMS which are created to meet the needs of today's world. NoSql DBMS are document oriented DBMS where data are normally store as json object similar to json structure in JavaScript.
They are not like traditional relational database management systems and support many cool features like speed, efficiency, replication etc. They are fast, open source, easy to use and can be upgraded at very low cost.
Performance and efficiency is major reason why Nosql databases are so popular in today's world. Don't get confused with DBMS and database, CouchDB is DBMS (database management system) and not a database.
Following are Some of the NoSql Data Base Management Systems
- Mongodb
- Redis
- CouchDB
What is CouchDB?
CouchDB is document oriented Nosql DBMS created and supported by apache.org. CouchDB is a DBMS that uses JSON structure for storing the documents, uses JavaScript for Map Reduce queries, and supports regular HTTP for interacting with the API.
CouchDB stores data in document and documents have JSON structure. CouchDB provides Restful HTTP API for reading and updating data/documents and hence we can store date; can access it from many platforms like mobile, web browser, through code.
Since it follows all the http rules its can be easily integrated to any applications which support http.
It is powerful and supports incremental replication, partition tolerant, ACID and hence it is the choice of programmer who what to use NoSql database. Each document has a unique id in CouchDB, so it is very rare any two documents will have same id. The Id can be generated dynamically.
Advantages of CouchDB
- Learning Curve : If you are aware of JSON, Restful API concepts and JavaScript, you can learn CouchDB easily without any effort.
- Multi-Version Concurrency Control (MVCC) Support: CouchDB read operations use a MVCC model in which each client will always see a consistent snapshot of the database from the beginning to the end of the read operation.
- Flexible Schema Designs : There is no enforcement in data structure for the document being stored. This flexibility gives you data-modeling choices to match your application and its performance requirements.
- Restful HTTP API : It provides restful API for reading and updating documents.
- Incremental Replication : Incremental replication is a process where document changes are periodically copied between servers.
- Consistency : All database clients see the same data, even with concurrent updates.
- Availability : All database clients are able to access some version of the data.
- Partition Tolerance : The database can be split over multiple servers.
Companies Depending on CouchDB
LotsOfWords.com, Anologue, imgb.in, PasteBooth, Fabulously40, ezistreet, UploadBooth, Scratch pad, Pixel This! , OurParents, Source Weaver, friendsell.com, I Got Cash 4 , FortyTwo, The Infinite Maze,
Basic Terminology Used in CouchDB
- DBMS : Database management system is what manages the database and its operations.
- JSON : It is a key / value pair based data interchange format used to interchange data between client and server. It is one of the most used data interchange format between client and server.
Installing CouchDB
Installing CouchDB on Windows
- Download and install the latest Windows binaries from CouchDB web site.
- Open up Futon (if you hadn't selected auto start CouchDB after installation, you have to start it first manually.)
Installing CouchDB on MAC
Using Zip
- Download CouchDB for Mac OS X .zip file from CouchDB website.
- Extract the Apache CouchDB .app into Applications Directory.
Using Brew
- pen /Applications/Installers/Xcode Tools/XcodeTools.mpkg
- brew install autoconf
- brew install autoconf-archive
- brew install automake
- brew install libtool
- brew install erlang
- brew install icu4c
- brew install spidermonkey
- brew install curl
- brew link icu4c
- brew link erlang
- brew install couchdb
- brew install erlang –no-docs
- sudo launchctl start org.apache.couchdb (to start CouchDB)
- sudo launchctl stop org.apache.couchdb (to restart CouchDB)
From port
- sudo port install CouchDB
- sudo port upgrade CouchDB
Installing CouchDB on UNIX (Linux, Ubuntu, Fedora)
- Install dependencies
- sudo apt-get install build-essential
- sudo apt-get install erlang-base-hipe
- sudo apt-get install erlang-dev
- sudo apt-get install erlang-manpages
- sudo apt-get install erlang-eunit
- sudo apt-get install erlang-nox
- sudo apt-get install libicu-dev
- sudo apt-get install libmozjs-dev
- sudo apt-get install libcurl4-openssl-dev
- ./configure
- make && sudo make install (or you can also use)
- sudo apt-get install couchdb –y
- sudo -i -u couchdb (to start CouchDB)
Different Ways to Interact With CouchDB
Using Inbuilt Futon Utility
We are going to use this since no additional installation is needed and available on all platform try in browser by typing url will open futon http://127.0.0.1:5984/\_utils/index.html
Using Curl
- Here for windows we need to install curl utility which you can download from www.confusedbycode.com/curl/ and install curl utility because curl isn't natively supported in window and download 32bit or 64 Bit based on which window OS you are using.
- Similar we need to find the support of curl on the system and install if not already installed or natively not supported.
Working with Futon Utility in CouchDB
Futon is a web-based interface built into CouchDB. It provides a basic interface to the majority of the functionality, including the ability to create, update, delete and view documents and views, provides access to the configuration parameters, and an interface for initiating replication.
Open the futon utility by typing http://127.0.0.1:5984/\_utils/index.html
in any browser of your choice.
The Main Sections in the Futon Utility Are
- Overview page : It provides a list of the databases and provides the interface for querying the database and creating and updating documents.
- Configuration : The interface allows you to edit the different configurable parameters. Replicator is an interface to the replication system, enabling you to initiate replication between local and remote databases.
- Status : This displays a list of the running background tasks on the server. Background tasks include view index building, compaction and replication. The Status page is an interface to the Active Tasks API call.
- Verify Installation : The Verify Installation allows you to check whether all of the components of your CouchDB installation are correctly installed.
- Test Suite : The Test Suite section allows you to run the built-in test suite. This executes a number of test routines entirely within your browser to test the API and functionality of your CouchDB installation. If you select this page, you can run the tests by using the Run All button.
Create Database
To create a database, click the Create Database ELLIPSIS button at the left top. You will be asked for the database name. Enter the desired name and click create button, the database is created.
Create Document
To create a document click on new document ellipsis button at the left top. CouchDB will create a document with unique _id click on correct image to save it.
Creating a Field Inside the Document
- Click the Add Field button.
- In the fieldname box, enter the name of the field you wish to create. E.g. “student_name”.
- Click the green tick next to the field name to confirm the field name change.
- Double-click the corresponding Value cell.
- Enter a student name, for example “John”.
- Click the green tick next to the field value to confirm the field value.
- The document is still not saved as this point. You must explicitly save the document by clicking the Save Document button at the top of the page.
Delete a Field
To delete a field just click on the (x) image at the start of the field and click save document button.
Update Document
Double-click the corresponding filed name and/ or value edit the date you want to. Click the green tick next to the field and/ or value and click on save document to explicitly save the updated document.
Delete Document
- To delete document you have to be inside that document. First click on the database on the overview page from which you want to delete the document.
- Click on the document you wish to delete. You will be inside that document then click on the delete document button at the top of the page.
Delete Database
To delete database click on the database you wish to delete on the overview page you will be inside that document. There will be list of document you have created Click delete database button at the top.
CouchDB: Using CURL
To check if CouchDB is up and running type the following in the command prompt curl http://127.0.0.1:5984/
Create/List Database
To create a database use the following in the command prompt
curl -X PUT http://127.0.0.1:5984/name_of_datbase
Where name\_of\_datbase
is the name of the database you want to create
To get details of a database, try the below command
curl -X GET http://127.0.0.1:5984/name\_of\_datbase
To get all the databases, type the below in the command prompt
curl -X GET http://127.0.0.1:5984/\_all\_dbs
Create Document
To create a document first create a database (Ex: student)
curl -X PUT http://127.0.0.1:5984/student
Create a stud.json file in any directory with the following content
{
"name": "john",
"surname": "Doe",
"type": "person"
}
Navigate to the directory where the json
is saved and type following command
curl -X POST http://127.0.0.1:5984/student/ -d @stud.json –H "Content-Type: application/json"
Get Document
To get the document type the following command. You need id of the document you want to view
curl -X GET http://127.0.0.1:5984/6097e1fb258f118f6c5fb0a64d03ade6
Update Document (\_rev no is required)
Create the updated json
file with \_rev
which you can get by querying get create the stud.json
with updated data like. \_rev
is most important
{
"\_rev":"1\_2902191555",
"name": "johnnew",
"surname": "Doe ne",
"type":"personnew"
}
Type the following command
curl -X PUT http://127.0.0.1:5984/albums/6e1295ed6c29495e54cc05947f18c8af -d @stud.json –H "Content-Type: application/json"
Delete Document (_rev no is required)
curl -X DELETE http://127.0.0.1:5984/student/b4bb85ab50271f3d12d25feb219cb66e -d '{"rev":"1-657551114"}'
Delete Database
curl -X DELETE http://localhost:8888/database\_name
Thank you for your time!
Posted on Utopian.io - Rewarding Open Source Contributors
Unfortunately, your contribution has been rejected due to the fact it is being too simple. I believe there are other documentations on this project (how to install etc.) and comparing this with those I do not really see a difference.
Need help? Write a ticket on https://support.utopian.io.
Chat with us on Discord.
[utopian-moderator]
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Congratulations @henrysblog! You have completed some achievement on Steemit and have been rewarded with new badge(s) :
Click on any badge to view your own Board of Honor on SteemitBoard.
For more information about SteemitBoard, click here
If you no longer want to receive notifications, reply to this comment with the word
STOP
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit