Reputation: 3341
How can I delete a document from couchdb using CouchRest, I have the document id. I guess it is something simple I am missing here.
I tried -
CouchRest.delete("http://localhost:5984/db/docid")
It throws an RestClient::ResourceNotFound: 404 Resource Not Found:
Could anybody throw some light on this issue please.
Cheers
Upvotes: 3
Views: 1681
Reputation: 81
couch = CouchRest.new("http://localhost:5984")
db = couch.database('db-name')
timestamp = Time.now
db.save_doc('_id' => 'doc', 'name' => 'test', 'date' => timestamp)
doc = db.get('doc') puts doc.inspect # #
db.delete_doc(doc)
Upvotes: 0
Reputation: 2626
In order to delete the document you need to know what its revision number is, and then send this back with the delete request. Easiest way to accomplish this is just to get the whole document and then call destroy on that document:
CouchRest.database("http://localhost:5984/databasename").get(doc_id).destroy()
Upvotes: 0
Reputation: 338
I don't use CouchRest, but according to your code, you may append a _rev
query parameter like this:
CouchRest.delete("http://localhost:5984/db/docid?_rev=docrev")
Upvotes: 1