couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brian Candler <B.Cand...@pobox.com>
Subject Re: post design documents
Date Tue, 02 Jun 2009 14:35:02 GMT
>   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")

Mime
View raw message