Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | Couchbase | Couchbase Server 2.0

Design docs (views) created via REST API don't work. "Show Results" is grayed out. 404 error in client.

13 replies [Last post]
  • Login or register to post comments
Tue, 10/02/2012 - 00:00
jinushaun
Offline
Joined: 10/01/2012
Groups: None

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?

Top
  • Login or register to post comments
Sun, 10/07/2012 - 10:41
ezrover
Offline
Joined: 09/19/2012
Groups: None

I have seen this problem also since Beta 2.0

Top
  • Login or register to post comments
Mon, 10/08/2012 - 13:44
mikew
Offline
Joined: 03/14/2011
Groups:

Which client library are you using?

Top
  • Login or register to post comments
Mon, 10/08/2012 - 22:27
dipti
Offline
Joined: 11/02/2011
Groups:

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. 

 

Top
  • Login or register to post comments
Tue, 10/09/2012 - 19:48
jinushaun
Offline
Joined: 10/01/2012
Groups: None

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.

Top
  • Login or register to post comments
Wed, 10/10/2012 - 15:59
jinushaun
Offline
Joined: 10/01/2012
Groups: None

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.

Top
  • Login or register to post comments
Wed, 10/17/2012 - 23:38
dipti
Offline
Joined: 11/02/2011
Groups:

are you using the "dev_" prefix when you name the design document? Only then will it be editable.

Top
  • Login or register to post comments
Thu, 10/18/2012 - 11:18
jinushaun
Offline
Joined: 10/01/2012
Groups: None

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.

Top
  • Login or register to post comments
Thu, 10/18/2012 - 11:50
john
Offline
Joined: 01/05/2012
Groups: None

Could you post a snippet of the code you used to create a design doc?

Top
  • Login or register to post comments
Tue, 10/23/2012 - 11:06
jamesterry
Offline
Joined: 10/23/2012
Groups: None

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

Top
  • Login or register to post comments
Thu, 11/01/2012 - 12:19
jinushaun
Offline
Joined: 10/01/2012
Groups: None

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.

Top
  • Login or register to post comments
Thu, 11/01/2012 - 12:30
jinushaun
Offline
Joined: 10/01/2012
Groups: None

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.

Top
  • Login or register to post comments
Thu, 11/01/2012 - 12:39
ezrover
Offline
Joined: 09/19/2012
Groups: None

Hi Jinushan, would you mind sharing your code to create views automatically?

Top
  • Login or register to post comments
Thu, 11/01/2012 - 12:59
jinushaun
Offline
Joined: 10/01/2012
Groups: None

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));

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker