Christoph
Christoph

Reputation: 28015

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.

Upvotes: 7

Views: 612

Answers (1)

Davorin Ruševljan
Davorin Ruševljan

Reputation: 4392

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

Upvotes: 3

Related Questions