Skip to content
This repository has been archived by the owner on Jul 22, 2019. It is now read-only.

Setting the _id field is not passed on to the DB #40

Closed
djc opened this issue Jul 12, 2014 · 2 comments
Closed

Setting the _id field is not passed on to the DB #40

djc opened this issue Jul 12, 2014 · 2 comments
Labels

Comments

@djc
Copy link
Owner

djc commented Jul 12, 2014

From simonmetson@googlemail.com on December 03, 2008 19:26:17

Hello,
Sorry if I'm missing something obvious, I only started playing with CouchDB yesterday, and it's been a long
week... ;)

If I create a document object:

dataset = client.Document()
dataset['_id'] = "/CSA07AllEvents/CMSSW_1_6_9-FastSim-1204301968/AOD"
dataset['key'] = ["/CSA07AllEvents/CMSSW_1_6_9-FastSim-1204301968/AOD", 0]
db.create(dataset)

I would expect that the _id of the object, once created in the db, would be the same as what I set it to. At the
moment it is lost, and a new one auto generated.

Likewise, if I do something like:

doc = {
... "_id": "the id I generate",
... "key": ["the id I generate", 0]
... }
db['thing'] = doc

the _id in the dictionary is over ridden by the db['thing'](though I can understand that).

I guess this would mean changing the Database.create() method, and given that's a short but sweet method
maybe this isn't practical. Doing the db['id I want'] is fine, but I think it would be neater if this was wrapped up in
the Document object (maybe it is and I'm missing something obvious...).

I ask because the application I'm evaluating using Couchdb (and it's python interface) for will have a lot of
GUID's already in place, and I don't really want/need a new one.
Cheers
Simon

Original issue: http://code.google.com/p/couchdb-python/issues/detail?id=39

@djc
Copy link
Owner Author

djc commented Jul 12, 2014

From simonmetson@googlemail.com on December 03, 2008 15:42:46

Just read Document.store(), sorry for the noise!

@djc
Copy link
Owner Author

djc commented Jul 12, 2014

From cmlenz on July 01, 2009 08:18:58

Database.create() should only be used when you want CouchDB to generate an ID for you. If you already have an
ID, you should use:

db[id] = doc

And yes, in that case, if the doc already has an _id field, it will be overwritten.

Maybe this is less clear than I had hoped, but I'm not sure making create() use an already supplied ID would be a
clean solution.

Status: WontFix

@djc djc closed this as completed Jul 12, 2014
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

1 participant