However, in the context of what we are doing, we would like to create these views one time, up front, during product installation and have the view definition published. To do that, we plan to use the CLI or even the N1QL tool to create the views. However, we haven’t found any documentation which explains how to create these views through the CLI or N1QL cbq. Is this possible? If it isn’t then are there any other recommendations or common practices users follow for view creation?
The N1QL command line tool is not intended to create design documents. If you use view-backed n1ql indexes one will be created for you if you specify CREATE INDEX … USING VIEWS basically.
In general we recommend using the SDKs to create views, although there are other ways to do it. On the CLI you can use cbdocloader which accepts a .zip file and if you do the right directory structure will populate the design documents as well (see http://developer.couchbase.com/documentation/server/4.1/cli/cbdocloader-tool.html). This also how we internally populate the sample buckets I think.
Thanks @daschl, that does help. I’m going to try out the REST API approach which fits well for us. I have been reading the docs and so far haven’t found a JSON structure/schema of the design document which can be used to create views through this REST API.
The document here Couchbase SDKs shows an example which states:
-d @byfield.ddoc
Specifies that the data payload should be loaded from the file byfield.ddoc.
But I haven’t found a sample content of such files. I do see a section which shows the response of a design doc creation:
So I can reverse engineer it to come up with a sample document file to add. But is there an example or document which shows what the design document that’s passed to the REST API (or even the .zip upload) should look like?
If you unzip the sample databases, you’ll find the design documents there in a file in a directory. The format is basically what you posted above.
Also, it’d be helpful to us if you click on the “feedback” link in the lower right to let us know where you’d like to get more info from the documentation. That creates an item for our docs team to follow up on.
Just did that on one of the docs. A minor feedback on the feedback process - when I provided the feedback in the window that popped up, it asked for name and email (both of which appeared optional). I provided my email but wasn’t aware (the feedback form didn’t state it either) that the email gets publicly displayed to everyone in the JIRA that gets created. Now that I see it publicly displayed, I wanted to request to remove it from the description of that JIRA but I don’t have a JIRA login and can’t create one myself.