Skip to content
This repository was archived by the owner on Jan 29, 2026. It is now read-only.

use existing _id if present when creating document#11

Open
anamba wants to merge 1 commit intoTechMagister:masterfrom
anamba:create-with-existing-id
Open

use existing _id if present when creating document#11
anamba wants to merge 1 commit intoTechMagister:masterfrom
anamba:create-with-existing-id

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 subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants