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

use existing _id if present when creating document #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

anamba
Copy link

@anamba anamba commented Nov 24, 2018

I found this helpful in my own app. But I'm new to CouchDB, so let me know if this is not a good practice.

@Schniz
Copy link
Contributor

Schniz commented Apr 15, 2019

Hey @anamba, and sorry that no one answered you yet!
I agree about the terminology being wrong. I believe it should support taking _id as a parameter and actually use it. But I also think that this can lead to an unexpected behavior:

client.create_document("test", {_id: "a", message: "hello"})
client.create_document("test", {_id: "a", message: "world"}) # will it throw? will it overwrite the data?

I'd say we don't want to overwrite, and that throwing an error is what we'd want to do. This will complicate create_document, which practically just maps itself to POST /#{db}. On the other hand, if we'll use client#update_document:

client.update_document("test", {_id: "a", message: "hello"})
client.update_document("test", {_id: "a", message: "world"}) # makes sense!

@anamba
Copy link
Author

anamba commented Apr 16, 2019

Both #create_document and #update_document PUT to a url that includes the id, so you're right, I suppose I could just use update_document and pass my own id. Just feels a little odd.

Either way, I'm thinking the presence or absence of _rev should take care of the issue you mentioned.

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

Successfully merging this pull request may close these issues.

2 participants