How to bulk import design docs and views to couchbase server



I am using couchbase server in a Java project build with Maven and I want to make some kind of import process every time the DB is deleted, so when I make a new deployment in the development environment, the design documents and the preloaded data are existing in the couchbase server instance.

So I have been trying to use the cbdocloader tool following these instructions:

In theory, this tool supports data and design documents load. I have tested it for documents and it works but I have tried for design documents but this is not working, I don get any error in the console but in the couchbase console there is no design document, what format should have the json?




Yes you can use the cbdocloader tool to import design documents/views.

You just need to create a folder and a file in your import directory/file. something like:


And in this file:

"_id": “_design/beer”,
“language”: “javascript”,
“views”: {
“brewery_beers”: {
“map”: “function(doc, meta) {\n switch(doc.type) {\n case “brewery”:\n emit([]);\n break;\n case “beer”:\n if (doc.brewery_id) {\n emit([doc.brewery_id,]);\n }\n break;\n }\n}\n”
“by_location”: {
“map”: “function (doc, meta) {\n if (, doc.state, {\n emit([, doc.state,], 1);\n } else if (, doc.state) {\n emit([, doc.state], 1);\n } else if ( {\n emit([], 1);\n }\n}”,
“reduce”: “_count”

I invite you to look in the file.

Note that you can always create views from your code too, as documented here:



Thank you very much! it works like a charm.


cbdocloader is used for load the ddoc and it will create the views with ddoc. Is my understanding is correct?