You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Stephan Bardubitzki <st...@bardubitzki.com> on 2012/07/07 04:21:25 UTC

Document update conflict

I'm using node and cradle to upload and save attachments (in this case 
images), however, I get a

error: conflict
reason: "document update conflict"
status: 409.

The right doc._id and doc._rev attributes are transmitted, what else can 
cause this error?

Here is my server side code:

exports.addLogo = function(req, res) {
     var business,
         businessName = req.body.businessname;
     if ( req.files ) {
         // get business data
         db.view('business/getByBusinessName', { key: businessName }, 
function(err, doc) {
             if ( err ) {
                 res.send({ header: 'Upload business logo', message: 
err.reason, type: 'error'});
             }
             else {
                 business = doc[0].value;
                 // add business logo to couchdb document
                 db.saveAttachment(
                     business._id,
                     business._rev,
                     req.files.logo.type,
                     fs.createReadStream(req.files.logo.path),
                     function( att_err, data ) {
                         if ( att_err ) {
                             console.log('Logo upload error: ' + 
att_err.reason);
                             res.send({ header: 'Upload business logo', 
message: att_err.reason, type: 'error'});
                         }
                         else {
                             console.log(data);
                             res.send({ response: 'ok' });
                         }
                 });
             }
         });

     }
};

Re: Document update conflict

Posted by Stephan Bardubitzki <st...@bardubitzki.com>.
Never mind, forgot the attachmentId.

On 12-07-06 07:21 PM, Stephan Bardubitzki wrote:
> I'm using node and cradle to upload and save attachments (in this case 
> images), however, I get a
>
> error: conflict
> reason: "document update conflict"
> status: 409.
>
> The right doc._id and doc._rev attributes are transmitted, what else 
> can cause this error?
>
> Here is my server side code:
>
> exports.addLogo = function(req, res) {
>     var business,
>         businessName = req.body.businessname;
>     if ( req.files ) {
>         // get business data
>         db.view('business/getByBusinessName', { key: businessName }, 
> function(err, doc) {
>             if ( err ) {
>                 res.send({ header: 'Upload business logo', message: 
> err.reason, type: 'error'});
>             }
>             else {
>                 business = doc[0].value;
>                 // add business logo to couchdb document
>                 db.saveAttachment(
>                     business._id,
>                     business._rev,
>                     req.files.logo.type,
>                     fs.createReadStream(req.files.logo.path),
>                     function( att_err, data ) {
>                         if ( att_err ) {
>                             console.log('Logo upload error: ' + 
> att_err.reason);
>                             res.send({ header: 'Upload business logo', 
> message: att_err.reason, type: 'error'});
>                         }
>                         else {
>                             console.log(data);
>                             res.send({ response: 'ok' });
>                         }
>                 });
>             }
>         });
>
>     }
> };