Brian,
Thanks.. I modified the file to the style you noted here and altered
the curl command from POST to PUT and it works fine. I get back the
"201 Created" header and my design document is now working.
curl -s -i -X PUT -H 'Content-Type: application/json' --data
@getFieldNamesDesign.js
'http://xxx.xxx.xxx.xxx:5984/jcoresgarden/_design/unique'
HTTP/1.1 201 Created
Server: CouchDB/0.9.0 (Erlang OTP/R12B)
Etag: "1-3118685883"
Date: Tue, 02 Jun 2009 15:12:39 GMT
Content-Type: text/plain;charset=utf-8
Content-Length: 55
Cache-Control: must-revalidate
If a person modifies the code and wants to upload a new version how is
that now done? I tried PUT again and get a "Document update conflict"
which I kinda expected. Then I tried a POST which gave me back a 500 error.
Do you have to DELETE the URI then re-PUT it or is there a mechanism to
update/version the design document?
Thanks
Doug
Brian Candler wrote:
The question is... I've tried some combinations, but can't seem to
get an approach that would allow me to post the map reduce code to a
_design document rather than just a _temp_view as in this example.
Your design document has to look like this:
{
"views": {
"my_first_view": {
"map":"...",
"reduce":"..."
}
}
}
Below is an example in Ruby, which should be easy to rewrite as a shell
script which uses curl.
HTH,
Brian.
---- 8< ----
require 'rubygems'
require 'restclient'
require 'json'
DB="http://127.0.0.1:5984/collator"
RestClient.delete DB rescue nil
RestClient.put "#{DB}",""
(32..126).each do |c|
RestClient.put "#{DB}/#{c.to_s(16)}", {"x"=>c.chr}.to_json
end
RestClient.put "#{DB}/_design/test", <<EOS
{
"views":{
"one":{
"map":"function (doc) { emit(doc.x,null); }"
}
}
}
EOS
puts RestClient.get("#{DB}/_design/test/_view/one")