Design docs (views) created via REST API don't work. "Show Results" is grayed out. 404 error in client.
I recently updated to the latest 2.0 beta release of Couchbase Server and now notice that when I upload design docs to Couchbase, they don't work. I get a 404 error when I try to access the view from the client library. If I view them in the web console, I notice that the "show results" button is grayed out. However, if I copy the design doc to dev and edit the view by pressing save without making any changes, the "show results" button is now enabled. If I publish this to production, the view works.
Is this by design? I did not have this issue in the earlier 2.0 releases. The REST API isn't very useful if I still have to use the web console to enable the views--especially when I have dozens of design docs and views.
UPDATE:
Problem was caused by carriage returns in view. I develop views on Windows in .js files and store them in Couchbase programmatically. Stripping out \r characters before sending the JSON to CouchbaseCluster.CreateDesignDocument() fixed the problem.
Is this considered a bug? Shouldn't the Couchbase server on Windows handle \r?
Which client library are you using?
When you create a view using the REST API, use the "dev_" prefix on the design document name to make it a "development view".
Example "_design/dev_beer" If this prefix doesn't exist, it will create a "production view". Production views are not editable, but as you mention you can copy them to dev if you create a production view.
Example: curl -X PUT -H'content-type:application/json' -d '{"views": {"name": {"map": "function (doc) {emit(doc.name), null}"}}}' http://ec2-xxx.us-west.compute...:8092/default/_design/dev_test-ddocs
{"ok":true,"id":"_design/dev_test-ddocs"}
In addition, for beta there have been changes to the way document metadata is handled.
Read more here:
http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-server-rn_2-0-0f.html
Hope this helps.
I've been doing this through the REST API instead of the client library, because I did not know that the C# client library was able to save design documents. The 2.0 documentation only mentions the REST API if you want to save design docs. However, I was recently informed via IRC that the documentation is outdated and that the C# client library can in fact save design documents!
https://github.com/couchbase/couchbase-net-client/blob/master/src/Couchb...
I will try that as soon as I can.
Updated my tool to use the SDK instead of the REST API. Same problem. Views return 404 when I try to use them until I "enable" them in the web console. I haven't updated my JSON yet to the new format, so that might the actual source of all my problems.
are you using the "dev_" prefix when you name the design document? Only then will it be editable.
I get this issue with or without the "dev_" prefix. I do not care about editing the view from the web console. I just want to be able to use a view that I *successfully* saved in Couchbase. When I call client.GetView().Key(foo), I get back 404 or no results. I see data in Couchbase and I can run the view manually in the web console, but I doesn't work in my client code until I "enable" it from the web console.
Could you post a snippet of the code you used to create a design doc?
You just provided the best way of design a doc,hope the visitors will get maximum of help,and if you want to get help in web designing just find us, web designer
Finally found time to tackle this problem again. I created a test project to see if I could duplicate this issue under other conditions. Unfortunately (or fortunately) I could not duplicate this problem in my tests. My real code still fails. Currently trying to pin-point what I'm doing differently between my real code and my tests. They're both using the same SDK version.
Ok, finally figured it out.
Couchbase does not accept views with carriage returns. I'm developing on windows, so I write my views in .js files and save them to Couchbase programmatically. Once I stripped out \r from my views, it worked.
Hi Jinushan, would you mind sharing your code to create views automatically?
Nothing special. It's in the official SDK, but undocumented for C#. (Documentation exists for Ruby, however) Had to look in the unit tests in GitHub to find their usage in C#
https://github.com/couchbase/couchbase-net-client/blob/master/src/Couchb...
The code below is C# specific, but any blob of JSON will do as long as it conforms to the design document format.
http://www.couchbase.com/docs/couchbase-manual-2.0/couchbase-views-desig...
var doc = new {
views = new
{
foobar = new
{
map = "function (doc, meta) { emit(meta.id, null); }"
}
}
};
var cluster = new Couchbase.Management.CouchbaseCluster("couchbase");
var success = cluster.CreateDesignDocument("bucketName", "docName", JsonConvert.SerializeObject(doc));
I have seen this problem also since Beta 2.0