CouchRest to delete document from couchdb
How can I delete a document from couchdb usi开发者_如何学Gong 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
You cannot delete a document without knowing its _rev
.
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")
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()
Access CouchDB
couch = CouchRest.new("http://localhost:5984")
db = couch.database('db-name')
timestamp = Time.now
Save a document, with ID
db.save_doc('_id' => 'doc', 'name' => 'test', 'date' => timestamp)
Fetch doc
doc = db.get('doc') puts doc.inspect # #
Delete
db.delete_doc(doc)
精彩评论