verdure
verdure

Reputation: 3341

CouchRest to delete document from couchdb

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

Answers (4)

Sandeep Singh Nagra
Sandeep Singh Nagra

Reputation: 81

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)

Upvotes: 0

Mike McKay
Mike McKay

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

ahmedyha
ahmedyha

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

Marcello Nuccio
Marcello Nuccio

Reputation: 3901

You cannot delete a document without knowing its _rev.

Upvotes: 2

Related Questions