couch_read.rb
#! /usr/bin/ruby
# -*- encoding: utf-8 -*-
#
# couch_read.rb
#
# Jul/31/2020
#
# ---------------------------------------------------------------------
require 'faraday'
require 'json'
#
# ---------------------------------------------------------------------
STDERR.puts "***start***"
#
URL="http://localhost:5984/nagano/_all_docs?include_docs=true"
#
res = Faraday.get URL
# puts res.status
json_str = res.body
dict_data=JSON.parse(json_str)
#
dict_data['rows'].each {|value|
doc = value["doc"]
str_out = doc["_id"] + "\t" + doc['name'] + "\t" \
+ doc["population"].to_s + "\t" + doc['date_mod']
print(str_out,"\n")
}
#
STDERR.puts "***End***"
# ---------------------------------------------------------------------
Run
./couch_read.rb
Recommended Posts