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.

Conor

On 18 December 2014 20:12:51 GMT+00:00, TAE JIN KIM <[email protected]> 
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?
>
>Thanks,
>
>> Date: Thu, 18 Dec 2014 23:41:50 +0400
>> Subject: Re: Validate_Doc_Update
>> From: [email protected]
>> To: [email protected]
>> 
>> 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 <[email protected]>
>wrote:
>> > Hello,
>> >
>> > Since CouchDB provides validate_doc_update, I thought that I might
>be able to provide some to check duplication here..
>> > like...
>> >
>> > 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 that..is there any way I can somehow
>access the existing documents from validate_doc_update function?
>> >
>> > Thanks,
>> >
>> >
>> >
>> >
>                                         

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

Reply via email to