Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I format CouchDB design documents in a human readable way?

Since views are defined with JSON in CouchDB I'm having a hard time defining those in a human readable fashion.

Take this document:

{
    "language": "javascript", 
    "views": {
        "by_location": {
            "map": "function(doc) { if (doc.location != null) emit(doc.location, doc) }" 
        }, 
        "by_location_tags": {
            "map": "function(doc) { if (doc.top_tags) { for(i=0;i<doc.top_tags.length;i++) { emit([doc.top_tags[i].tag_name, doc.location], doc); } } }"
        }
    }
}

Writing the map function as one long string is plain ugly and it's insanely hard to spot bugs. I wonder what is the workflow for defining views in CouchDB? I feel as I'm missing the obvious.

like image 272
Christoph Avatar asked Sep 02 '13 16:09

Christoph


Video Answer


1 Answers

In addition to mentioned Futon, there are several tools that allow you to write your map and view functions with your favorite editors and save them on your local file system. Those tools than take care of "pushing" your code to CouchDB.

You can find more about those tools here

like image 190
Davorin Ruševljan Avatar answered Oct 03 '22 00:10

Davorin Ruševljan