couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject RE: Validate_Doc_Update
Date Thu, 18 Dec 2014 20:23:53 GMT
Yes, that's absolutely true that I can provide my own _id ..then it will return conflict staust
if it is duplicated. HOWEVER, what I was asking,  "Other than _id"..

Subject: RE: Validate_Doc_Update
Date: Thu, 18 Dec 2014 20:21:00 +0000

You could assign your own ids that describe the contents of the document. ie. POST your own
'_id' field when creating the document. If the '_id' exists it will fail with an update conflict
- stopping duplicate data from being inserted.


On 18 December 2014 20:12:51 GMT+00:00, TAE JIN KIM <> wrote:
So other than _id(which is uuid CouchDB provides automatically if not specified explicitly
for the entire database), there is no some elegant(?) way  to prevent creating duplicate data
inside CouchDB?


 Date: Thu, 18 Dec 2014 23:41:50 +0400
 Subject: Re: Validate_Doc_Update
 No, that's not possible. Validate doc update function only operates
 with document's new version candidate and the "old", current one. It
 cannot not access to others since this will slow down whole the
 process and break eventual consistency. You should run this check
 outside CouchDB in your client code before PUT the document.
 On Thu, Dec 18, 2014 at 10:36 PM, TAE JIN KIM <>

 Since CouchDB provides validate_doc_update, I thought that I might be able to provide some
to check duplication here..

 function(newDoc,oldDoc,userCtx) {
       if(newDoc.type == "myCustomType") {
               // here..something like..
               // check newDoc against the existing documents of "myCustomType" to see whether
there was already same data or not..
              // for example,
             //  getExistingDocumentsByType("myCustomType").forEach(function(doc) {
            //               if(newDoc.mydata == doc.mydata) {
             //                       ///Boom..throw error..
              //              }
               //    });

 Is this something possible? Well..obviously there is no provided
getExistingDocumentsByType function from couchdb.....just was trying to show what I was trying
to achieve...

 So ultimately, my question is there any way I can somehow access the existing documents
from validate_doc_update function?




Sent from my Android device with K-9 Mail. Please excuse my brevity. 		 	   		  
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message