Edit CouchDB design document with curl
$ curl -X PUT http://localhost:5984/koi
{" ok" :true}
$ curl -X POST http://localhost:5984/koi -d ' {"name":"alice","age":25}' -H' Content-Type:application/json'
{" ok" :true," id" :" 9bb525a9771672ab8578f82d01001702" ," rev" :" 1-d9b27c5ae36c3e7e25bfaab1fb912e90" }
create design document that uses documents' "name" attribute as a key
$ curl -X PUT http://localhost:5984/koi/_design/ddoc -d ' {"views":{"name":{"map":"function(doc) { emit(doc.name); }"}}}' -H' Content-Type:application/json'
{" ok" :true," id" :" _design/ddoc" ," rev" :" 1-30aab27827e54bda77a5ac9ae6b72f6c" }
confirm we have a new built index
$ curl http://localhost:5984/koi/_design/ddoc/_view/name
{" total_rows" :1," offset" :0," rows" :[
{" id" :" 9bb525a9771672ab8578f82d01001b8b" ," key" :" alice" ," value" :null}
]}
save design document into file
$ curl http://localhost:5984/koi/_design/ddoc -o ddoc.json -s
$ cat ddoc.json
{" _id" :" _design/ddoc" ," _rev" :" 1-30aab27827e54bda77a5ac9ae6b72f6c" ," views" :{" name" :{" map" :" function(doc) { emit(doc.name); }" }}}
edit design document in file "ddoc.json" and make it also emit value of documents' "age" attribute
$ vi ddoc.json
{
" _id" : " _design/ddoc" ,
" _rev" : " 1-30aab27827e54bda77a5ac9ae6b72f6c" ,
" views" : {
" name" : {
" map" : " function(doc) { emit(doc.name, doc.age); }"
}
}
}
:wq
$ curl -X PUT http://localhost:5984/koi/_design/ddoc --data @ddoc.json -H' Content-Type:application/json'
{" ok" :true," id" :" _design/ddoc" ," rev" :" 2-969b8f6ac9911b15c7884d9d5d527093" }
confirm we have index updated and emitting both "name" and "age"
$ curl http://localhost:5984/koi/_design/ddoc/_view/name
{" total_rows" :1," offset" :0," rows" :[
{" id" :" 9bb525a9771672ab8578f82d01001b8b" ," key" :" alice" ," value" :25}
]}