3

When I try to add design documents (beginning with "_") I get an error "Only reserved document ids may start with underscore." How can I add a design document?

Andrew Campoli
  • 222
  • 1
  • 13

1 Answers1

2

According to the Definitive Guide, a design document like this one:

{
  "_id" : "_design/example",
  "views" : {
    "foo" : {
      "map" : "function(doc){ emit(doc._id, doc._rev)}"
    }
  }
}

can be added to the database named basic with a curl command like this:

curl -X PUT http://127.0.0.1:5984/basic/_design/example --data-binary @mydesign.json

Personally, I find it much easier to use CouchApp to add and manage design documents. This section of the Definitive Guide describes how to install and use it.

lambmj
  • 1,843
  • 2
  • 21
  • 27
  • Ya I have looked over the Definitive Guide. I am also reading about and beginning to play with it. However, when I try "curl -X PUT http://127.0.0.1:5984/basic/_design/example --data-binary @mydesign.js" and when I try to add a design document through Futon (in the browser) I get the error '{"error":"bad_request","reason":"Only reserved document ids may start with underscore."}'. – Andrew Campoli Sep 24 '12 at 17:02
  • Funny, I just tried it again and it works fine for me. `curl -X PUT http://127.0.0.1:5984/g3/_design/example --data-binary @mydesign.json` `{"ok":true,"id":"_design/example","rev":"1-230141dfa7e07c3dbfef0789bf11773a"}` What version of CouchDB are you using? – lambmj Sep 24 '12 at 17:20
  • I'm using version 1.2.0 which I believe is the current. – Andrew Campoli Sep 24 '12 at 18:41
  • Yes it is and it is the same version I'm using. Can you update your question with the design document you're trying to upload? – lambmj Sep 24 '12 at 19:01
  • I have tried uploading many different JSONs to see if the file to be PUT was the issue. However, I get the same error even when I do "curl -X PUT http://127.0.0.1:5984/tweetaction/_design/" which I believe is the correct syntax for posting a blank design document. – Andrew Campoli Sep 24 '12 at 19:16
  • 3
    I don't believe that is the correct syntax for creating a blank design document. It doesn't provide an _id for the design document. When I try it I get the same error. If you want to create a blank design document you must pvide a full _id and some json. For example, this works for me to create an empty design document: `curl -X PUT http://127.0.0.1:5984/test/_design/blank --data-binary "{}"` – lambmj Sep 24 '12 at 19:25