Records are CouchDB's focal information structure. Substance of the information base will be put away as Documents rather than tables. You can make these records utilizing cURL utility given by CouchDB, just as Futon. This part covers the approaches to make a report in an information base.
Each record in CouchDB has an exceptional ID. You can pick your own ID that ought to be as a string. For the most part, UUID (Universally Unique IDentifier) is utilized, which are irregular numbers that have least possibility of making a copy. These are liked to keep away from crashes.
Making a Document utilizing cURL Utility
You can make a report in CouchDB by sending a HTTP solicitation to the worker utilizing PUT technique through cURL utility. Following is the linguistic structure to make an archive.
$ curl -X PUT http://127.0.0.1:5984/database name/"id" -d ' { document} '
Utilizing −X, we can indicate a custom solicitation technique for HTTP we are utilizing, while at the same time speaking with the HTTP worker. For this situation, we are utilizing PUT technique. At the point when we utilize the PUT strategy, the substance of the url determines the article name we are making utilizing the HTTP demand. Here we need to send the accompanying −
- The name of the data set name in which we are making the record.
- The archive id.
- The information of the archive. −d choice is utilized to send the information/record through HTTP demand. While composing a record essentially enter your Field-Value sets isolated by colon, inside blossom sections as demonstrated underneath −
{
Name : Raju
age : 23
Designation : Designer
}
Model
Utilizing the above given punctuation in the event that you need to make a record with id 001 of every a data set with name my_database, you can make it as demonstrated underneath.
$ curl -X PUT http://127.0.0.1:5984/my_database/"001" -d
'{ " Name " : " Raju " , " age " :" 23 " , " Designation " : " Designer " }'
{"ok":true,"id":"001","rev":"1-1c2fae390fa5475d9b809301bbf3f25e"}
The reaction of CouchDB to this solicitation contains three fields −
- "Alright", demonstrating the activity was fruitful.
- "id", which stores the id of the record and
- "fire up", this demonstrates the modification id. Each time you amend (refresh or alter) a record a _rev worth will be produced by CouchDB. On the off chance that you need to refresh or erase a report, CouchDB anticipates that you should incorporate the _rev field of the correction you wish to change. At the point when CouchDB acknowledges the change, it will create another update number. This system guarantees simultaneousness control.
Check
In the event that you need to see the made report you can make it utilize the archive as demonstrated beneath.
$ curl -X GET http://127.0.0.1:5984/my_database/001
{
"_id": "001",
"_rev": "1-3fcc78daac7a90803f0a5e383f4f1e1e",
"Name": "Raju",
"age": 23,
"Designation": "Designer"
}
Making a Document utilizing Futon
To Create a record open the http://127.0.0.1:5984/_utils/url to get an Overview/list page of CouchDB as demonstrated beneath.
Select the information base in which you need to make the archive. Open the Overview page of the information base and select New Document alternative as demonstrated underneath.
At the point when you select the New Document choice, CouchDB makes another data set record, doling out it another id. You can alter the estimation of the id and can appoint your own an incentive as a string. In the accompanying outline, we have made another archive with an id 001.
In this page, you can notice three choices − save Document, Add Field and Upload Attachment.
Add Field to the Document
To add field to the report click on Add Field choice. In the wake of making a data set, you can add a field to it utilizing this alternative. Tapping on it will get you a couple of text boxes, specifically, Field, esteem. You can alter these qualities by tapping on them. Alter those qualities and type your ideal Field-Value pair. Snap on the green catch to save these qualities.
In the accompanying delineation, we have made three fields Name, age and, Designation of the worker.
Save Document
You can save the progressions made to the archive by tapping on this choice. Subsequent to saving, another id _rev will be produced as demonstrated underneath.
