Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document revision value requirement when updating #498

Closed
Aaron-Zhao opened this issue Apr 27, 2017 · 4 comments
Closed

Document revision value requirement when updating #498

Aaron-Zhao opened this issue Apr 27, 2017 · 4 comments

Comments

@Aaron-Zhao
Copy link

It seems like CouchDB 2 no longer requires revision value for updating an existing document (PUT /{db}/{docid}). It always updates the newest version of the document.

But attaching a file to a document (PUT /{db}/{docid}/{attname}) still requires a revision value.

Can we in the future just default rev to the newest version for attachments?

@wohali
Copy link
Member

wohali commented Apr 27, 2017

I think you are mistaken in your belief that CouchDB no longer requires the revision value for updating a document.

$ curl -X PUT localhost:5984/foo
{"ok":true}
$ curl -X PUT localhost:5984/foo/bar -d '{"joan": "is great"}'
{"ok":true,"id":"bar","rev":"1-9b0890fa11b66dc9f0cc4917e11553d1"}
$ curl localhost:5984/foo/bar
{"_id":"bar","_rev":"1-9b0890fa11b66dc9f0cc4917e11553d1","joan":"is great"}
$ curl -X PUT localhost:5984/foo/bar -d '{"joan": "is still great"}'
{"error":"conflict","reason":"Document update conflict."}

@wohali wohali closed this as completed Apr 27, 2017
@Aaron-Zhao
Copy link
Author

You're right. It still requires rev for updates. Sorry, I wasn't aware of that I actually had rev passed in the call.

Just curious, why would CouchDB team decided to have rev as required for an update? Why not design it as what GET /{db}/{docid} is where the default is always the latest rev if previous rev is wanted we can always pass it in the query parameter.

@wohali
Copy link
Member

wohali commented Apr 27, 2017

Because CouchDB is eventually consistent by design - our entire replication structure (the key feature of CouchDB) requires revisions to be part of the API to ensure consistency. You can learn more about this at http:https://guide.couchdb.org/draft/consistency.html

@Aaron-Zhao
Copy link
Author

Thanks for the info! That's helpful.

nickva pushed a commit to nickva/couchdb that referenced this issue Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants