CouchDB - SPLessons

CouchDB Create Documents

Home > Lesson > Chapter 8
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

CouchDB Create Documents

CouchDB Create Documents

shape Description

The central database structures in CouchDB is said to be a document and the essence of the database are saved in terms of documents rather then tabular forms and these documents can be created based on Futon and with utility of cURL.

Document creating using Futon

shape Description

The following steps describes the process of creating a document using futon.

shape Step - 1

For creating a database document open http://127.0.0.1:5984/_utils/.

shape Step - 2

Click on splessons1.

shape Step - 3

Click on New Document.

shape Step - 4

Enter _id value and click tick button.

shape Step - 5

Click on Add Field.

shape Step - 6

Enter the new field values and click tick button.

shape Step - 7

Entered field names with null values.

shape Step - 8

Click on source button.

shape Step - 9

The source code will display the documents with null values.

Document creating using cURL Utility

shape Description

Database documents can be created in CouchDB by passing a HTTP solicitation to the server utilizing PUT techniques over the utility of cURL.

shape Syntax

The syntax for creating a document using cURL utility.
$ curl -X PUT http://127.0.0.1:5984/database name/"id" -d ' { document} ' X => HTTP request. PUT => Operation/methods in the url's. -d => Sending the documents through HTTP request.

shape Examples

By viewing the below example, the concept of creating a document can  be easily understand. [c] $ curl -X PUT http://127.0.0.1:5984/my_database/"001" -d '{ " Name " : " Mike " , " age " :" 25 " , " Designation " : " Database Administrator" }' {"ok":true,"id":"001","rev":"1-1c2fae390fa5475d9b809301bbf3f25e"} $ curl -X GET http://127.0.0.1:5984/my_database/001 { "_id": "001", "_rev": "1-3fcc78daac7a90803f0a5e383f4f1e1e", "Name": "Mike", "age": 25, "Designation": "Database Administrator" } [/c] Here in the above example a document as been successfully created and get verified that whether all the value in the document exists are not.

Summary

shape Key Points

  • Creating a document - Document created in couchDB database.
  • Creating document using futon - The process of creating a new database document.
  • Creating document using cURL utility - Created by passing a HTTP solicitation to the server using PUT techniques.