- CouchDB - Attaching Files
- CouchDB - Deleting a Document
- CouchDB - Updating a Document
- CouchDB - Creating a Document
- CouchDB - Deleting a Database
- CouchDB - Creating a Database
- CouchDB - HTTP API
- CouchDB - Curl & Futon
- CouchDB - Installation
- CouchDB - Introduction
- CouchDB - Home
CouchDB Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
CouchDB - Creating a Database
Database is the outermost data structure in CouchDB where your documents are stored. You can create these databases using cURL utipty provided by CouchDB, as well as Futon the web interface of CouchDB.
Creating a Database using cURL Utipty
You can create a database in CouchDB by sending an HTTP request to the server using PUT method through cURL utipty. Following is the syntax to create a database −
$ curl -X PUT http://127.0.0.1:5984/database name
Using −X we can specify HTTP custom request method to be used. In this case, we are using PUT method. When we use the PUT operation/method, the content of the url specifies the object name we are creating using HTTP request. Here we have to send the name of the database using put request in the url to create a database.
Example
Using the above given syntax if you want to create a database with name my_database, you can create it as follows
curl -X PUT http://127.0.0.1:5984/my_database { "ok":true }
As a response the server will return you a JSON document with content “ok” − true indicating the operation was successful.
Verification
Verify whether the database is created, by psting out all the databases as shown below. Here you can observe the name of a newly created database, " my_database " in the pst.
$ curl -X GET http://127.0.0.1:5984/_all_dbs [ "_reppcator " , " _users " , " my_database " ]
Creating a Database using Futon
To create a database open the http://127.0.0.1:5984/_utils/. You will get an Overview/index page of CouchDB as shown below.
In this page, you can see the pst of databases in CouchDB, an option button Create Database on the left hand side.
Now cpck on the create database pnk. You can see a popup window Create New Databases asking for the database name for the new database. Choose any name following the mentioned criteria. Here we are creating another database with name tutorials_point. Cpck on the create button as shown in the following screenshot.
Advertisements