Couchdb: Jerry, Nic, and Omer
Couchdb: Jerry, Nic, and Omer
CouchDB Relax
CouchDB
Revision control exists for this purpose; each document has a revision
number which can be used to compare to another document's
revision number.
Introduction to JSON
"userName":"Mark",
"age":33,
"gender":"M"
}
JSON Constructs
More Examples:
{
"fruitName": "apple",
"color": "green",
"numberOfSeeds": 5,
"parentTypes": [
"Granny Smith",
"Ambrosia"
]
String data
String data
Integer data
Array
GET
Retrieve database information or documents.
curl X GET host:port/db_name
HEAD
Head returns the basic information of the document.
curl X HEAD host:port/db_name/doc_id
It will only delete the document if you provided with the correct
rev
curl X PUT host:port/db_name/doc_id?rev=/ -d
{}
This will overwrite the original document with the same id.
http://wiki.apache.org/couchdb/HTTP_Document_API
VIEW
After you created the database and the documents you can
then create views (used like queries).
We can do views in cURL, but it is difficult to PUT, UPDATE,
DELETE views through cURL. It is easier to do it through Futon.
Views
function (doc) {}
doc is the current document being processed; each document goes though the map one
by one
Examples:
function(doc){
emit(doc.name,doc.age);
}
function(doc){
if(doc.scores.name){
for(var i in soc.scores)
emit(doc.scores[i].name,doc.scores[i].score)
}
}