Create a gist now

Instantly share code, notes, and snippets.

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