Skip to content

Instantly share code, notes, and snippets.

@edbond
Created June 26, 2009 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edbond/136563 to your computer and use it in GitHub Desktop.
Save edbond/136563 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'couchrest'
db = CouchRest.database!("http://127.0.0.1:5984/loans")
db.recreate!
doc1 = db.save_doc({:loan_amount => 40000, :loan_period => 4})
doc2 = db.save_doc({:loan_amount => 20000, :loan_period => 2})
doc3 = db.save_doc({:loan_amount => 50000, :loan_period => 9})
db.save_doc({
"_id" => "_design/loans",
:views => {
:test => {
:map => "function(doc) { emit([doc.loan_amount, doc.loan_period], doc) }"
}
}
})
puts db.view("loans/test", {:startkey => [30000, 5], :endkey => [{},{}]})['rows'].inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment