2

I am using couchdb through couchrest in a ruby on rails application. When I try to use futon it alerts with a message box saying bad_utf8_character_code. If I try to access records from rails console using Model.all it raises either of 500:internal server error, RestClient::ServerBrokeConnection: Server broke connection: or Errno::ECONNREFUSED: Connection refused - connect(2) Could any one help me to sort this issue?

Pravin
  • 6,592
  • 4
  • 42
  • 51

1 Answers1

0

I ran into this issue. I tried various curl calls to delete, modify, and even just view the offending document. None of them worked. Finally, I decided to pull the documents down to my local machine one at a time, skip the "bad" one, and then replicate from my local out to production.

  • Disable app (so no more records are being written to the db)

  • Delete and recreate local database (run these commands in a shell):

    curl -X DELETE http://127.0.0.1:5984/mydb
    curl -X PUT http://127.0.0.1:5984/mydb
    
  • Pull down documents from live to local using this ruby script

require 'bundler'
require 'json'

all_docs = JSON.parse(`curl http://server.com:5984/mydb/_all_docs`)
docs = all_docs['rows']
ids = docs.map{|doc| doc['id']}
bad_ids = ['196ee4a2649b966b13c97672e8863c49']

good_ids = ids - bad_ids

good_ids.each do |curr_id|
  curr_doc = JSON.parse(`curl http://server.com:5984/mydb/#{curr_id}`)
  curr_doc.delete('_id')
  curr_doc.delete('_rev')
  data = curr_doc.to_json.gsub("\\'", "\'").gsub('"','\"')
  cmd = %Q~curl -X PUT http://127.0.0.1:5984/mydb/#{curr_id} -d "#{data}"~
  puts cmd
  `#{cmd}`
end
  • Destroy (delete) and recreate production database (I did this in futon)

  • Replicate

    curl -X POST http://127.0.0.1:5984/_replicate -d '{"target":"http://server.com:5984/mydb", "source":"http://127.0.0.1:5984/mydb"}' -H "Content-Type: application/json"
    
  • Restart app

rude-n8
  • 196
  • 2
  • 8