简体   繁体   中英

Issue with CouchDB

In the TAMA implementation, I came across an issue with Couchdb. (Version 1.2.0) ,

We are using named documents to maintain unique constraint logic in the application. (named documents : whose _id is user defined, and not couch generated.)

We are using the REST API to add the documents to Couchdb, where we found strange behavior :

When we try to recreate the documents using HTTP PUT which have been deleted in the past(because of bug in the code), the documents are not created the first time .

HTTP Put - Returns HTTP 200, but doc is not saved in couchdb. 
Again trying the same request, 
HTTP Put - Returns HTTP 200 and adds the doc in database.

HTTP PUT request needs to be sent twice to create and save the doc.

I have checked that the above bug is reproducible for deleted docs, ie the response for GET _id is {"error":"not_found","reason":"deleted"}.

This looks like a bug in CouchDB to me, could you please let us know if you could think of any scenario where above error might occur and any possible workarounds/solutions ?

Couchdb has a builtin mechanism to ensure that you do not overwrite the same document as someone else.

If you PUT any existing document, you'll have to accompany this process with the current doc._rev value, so that couchdb can confirm the document you are updating is based on the most recent version in the database.

I've not come across this case with deletions, but it makes sense to me that couchdb should not allow you to overwrite a deleted document as the assumption should be, you just don't know about the deletion.

Have you tried if you can access the revision of the deleted document and if so, whether by adding it to the new document, you can succeed with the PUT on the first call?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM