Skip to content
This repository has been archived by the owner on Nov 5, 2018. It is now read-only.

Couch returning 409's #45

Closed
xsyn opened this issue Dec 7, 2011 · 8 comments
Closed

Couch returning 409's #45

xsyn opened this issue Dec 7, 2011 · 8 comments
Labels

Comments

@xsyn
Copy link

xsyn commented Dec 7, 2011

I've read through the documentation, and I may be doing this wrong, but when I try to insert an image, from file, into a currently existing document and I do:

      fs.createReadStream(doc.image.path).pipe(
                      db.attachment.insert(doc._id, doc.image.name, {}, doc.image.mime)                        
     );

I get back a 409 from couchdb, am I implementing this incorrectly?

@jhs
Copy link
Collaborator

jhs commented Dec 7, 2011

Well, the underlying error is that attaching (or deleting attachments) is just a normal update to a document. It requires a revision ID just like any other update.

You can either add ?rev=... to the query string (path), or add a header If-Match: .... See the attachment documentation.

What would be great is for nano to do the right thing transparently, either fetching first to get a revision, or else add the correct header if the _rev is known.

@dscape
Copy link
Contributor

dscape commented Dec 7, 2011

Can I ask you where did you learn about nano? If it was a blogpost I would like to cross post this response.

409 means conflict. Meaning you are trying to update but not specifying the rev.

If this isn't enough help I got this from the documentation regarding specifying revs:

https://github.com/dscape/nano/blob/master/nano.js#L467-#L470

So you need to get the document, see the latest rev, and update the attachment according to the rev.

Or you can simply delete the document which will reset the rev.

If this isn't enough I can write a working example.

Also advice you to read the free CouchDB book by @jchris http://guide.couchdb.org/editions/1/en/index.html

@dscape
Copy link
Contributor

dscape commented Dec 7, 2011

What would be great is for nano to do the right thing transparently, either fetching first to get a revision, or else add the correct header if the _rev is known.

@jhs do you think this would be expected behavior? I would expect it to throw 409 if I don't know the rev, e.g. I might be updating the wrong attachment ?

@xsyn
Copy link
Author

xsyn commented Dec 7, 2011

Hi all,

I found the problem. I was doing a check on the revision, but because it was doing an update before adding the attachment the revision number was changing.

Dscape: I found nano through a friend, and he pointed me to this site: http://writings.nunojob.com/2011/08/nano-minimalistic-couchdb-client-for-nodejs.html

@dscape
Copy link
Contributor

dscape commented Dec 7, 2011

Great @xsyn - btw doing a cms in a document database makes a lot of sense :) doing it in a relational db, not so much :P

@dscape dscape closed this as completed Dec 7, 2011
@xsyn
Copy link
Author

xsyn commented Dec 7, 2011

:) I'm still getting my head around the user management though.

Thanks for your help.

@dscape
Copy link
Contributor

dscape commented Dec 7, 2011

There's a special _users database where you store your users.

Check the session tests for some pointers

@jhs
Copy link
Collaborator

jhs commented Dec 7, 2011

@dscape yes, sorry, I misunderstood. For some reason I thought the doc was already known in state somewhere.

KangTheTerrible pushed a commit to KangTheTerrible/nano that referenced this issue Aug 19, 2018
We now test against latest stable, latest v4, latest v6 and latest v7
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants