How to import views correctly?

Hi guys, through Google, I found an article in this forum about “How to bulk import design docs and views to couchbase server”, but in practice, I still run into problems for importing views successfully. Here is the details.

// in my shell script file, I have …
cbdocloader -n 127.0.0.1:8091 -u $ADMIN_LOGIN -p $ADMIN_PASSWORD -b audit_bucket_name /staticDocs/auditData

cbdocloader -n 127.0.0.1:8092 -u $ADMIN_LOGIN -p $ADMIN_PASSWORD -b security_bucket_name /design_docs

// Under the ‘desidn_docs’ sub-folder, I have a json file whose content is simplified as follows
{
“id”: “design/dev_views”,
“language”: “javascript”,
“views”: {
“GetDocuments” : {
“map”: “function (doc, meta) { emit(meta.id, null); }”
}
}

After I run the shell script, from couchbase web console, I can see that the static document is imported to couchbase server successfully (under the ‘audit_bucket_name’ bucket, but I did not see the view in the ‘security_bucket_name’ bucket.

I am not clear where it went wrong. Is that command not specified correctly? or the json design document is not defined correctly? Please point it to me where it went wrong, your help is really appreciated.

Hi @byuan,

Would you mind attaching an example zip file, so I could try it? I’m not able to reproduce the issue on my own. Also, what version of Couchbase Server are you using?

Hi Matthew,

Thank you for the help. Attach to this email is one design document ‘myviews.json’ I placed in the ‘design_docs’ sub-folder of my project.

The command I used to import views is:

cbdocloader -n 127.0.0.1:8091 -u $ADMIN_LOGIN -p $ADMIN_PASSWORD -b data_bucket /design_docs

I noticed that if I run the above command, it will only load the json file/data into the data_bucket as a document, not as a view.

And if I try to use port 8092 in the above command, I got the following error messages

Traceback (most recent call last):
File “/opt/couchbase/lib/python/cbdocloader”, line 190, in
pump_transfer.exit_handler(DocLoader().main(sys.argv))
File “/opt/couchbase/lib/python/cbdocloader”, line 178, in main
self.init_bucket()
File “/opt/couchbase/lib/python/cbdocloader”, line 91, in init_bucket
self.rest = RestConnection(server_info)
File “/opt/couchbase/lib/python/couchbase/rest_client.py”, line 187, in init
self.couch_api_base = config[“nodes”][0].get(“couchApiBase”)
KeyError: ‘nodes’

Bo

Hi Matthew,

This is Bo again. Sorry I forgot to mention in last email that I am using Couchbase 4.1.0.

Also, from the examples of the following link

https://developer.couchbase.com/documentation/server/current/cli/cbdocloader-tool.html

I noticed that it uploads JSON from a .zip file. For that reason, in my latest test, I zipped my json file to a zip file and replaced the json file with the zip file in my ‘design_docs’ folder. This time, running the cbdocloader didn’t even load the zip file.

Bo

Hi @byuan,

Thanks, but it looks like the attachment didn’t work (or maybe you forgot it).

Matthew, I cannot upload/attach a zip file because I got an error message from the email server, saying that 'new users cannot upload/attach files"

@byuan,

You can send it to my email address: matthew.groves@couchbase.com or share a dropbox link or whatever is convenient for you.