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

Can't create a named document #27

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

Can't create a named document #27

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

Comments

@djc
Copy link
Owner

djc commented Jul 12, 2014

From wjh...@gmail.com on October 14, 2008 03:25:36

What steps will reproduce the problem? 1. db.create({'_id': 'hi', 'contents':'ho'})
u'f37d8d5594fa8dd9b0c4642269275343'

db["hi"]
Traceback (most recent call last):
File "", line 1, in
File
"/usr/lib/python2.5/site-packages/CouchDB-0.4-py2.5.egg/couchdb/client.py",
line 253, in getitem
File
"/usr/lib/python2.5/site-packages/CouchDB-0.4-py2.5.egg/couchdb/client.py",
line 646, in get
File
"/usr/lib/python2.5/site-packages/CouchDB-0.4-py2.5.egg/couchdb/client.py",
line 688, in _request
couchdb.client.ResourceNotFound: (u'not_found', u'missing') What is the expected output? What do you see instead? Personally (and tied w/ a previous comment) I'd expect to be able to create
documenta via;
db["new_doc"] = { 'contents': 'foo', 'bar' : True }
but I could understand if that needed to be;
db.create( '_id': "new_doc", 'contents': 'foo', 'bar' : True) What version of the product are you using? On what operating system? >>> couchdb.version
'0.4' Please provide any additional information below. BTW though I love the library! I'm not the code guy I'd like to be but it's
been helpful to actually be able to read your code (it's taught me about
couchdb's REST API and python too).

Thanks for the work!

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

@djc
Copy link
Owner Author

djc commented Jul 12, 2014

From cmlenz on November 05, 2008 09:02:34

This works for me. Please note that the database (represented by the db variable in your example) does need
to exist. If it does, you should be able to create a document using either method. In fact db.create is intended
for use when you want CouchDB to generate the ID for you.

Status: WorksForMe

@djc
Copy link
Owner Author

djc commented Jul 12, 2014

From wjh...@gmail.com on November 05, 2008 10:26:31

In this example the Database "files" exists...

s = couchdb.Server("http://192.168.1.99:5984/"
db = s['files']
f = db['foo'] = "{'_id': 'hi', 'contents':'ho'}"
Traceback (most recent call last):
File "", line 1, in
File "/usr/lib/python2.5/site-packages/CouchDB-0.4-py2.5.egg/couchdb/client.py",
line 263, in setitem
File "/usr/lib/python2.5/site-packages/CouchDB-0.4-py2.5.egg/couchdb/client.py",
line 657, in put
File "/usr/lib/python2.5/site-packages/CouchDB-0.4-py2.5.egg/couchdb/client.py",
line 694, in _request
couchdb.client.ServerError: (500, (u'EXIT', u'{function_clause,[{cjson,tokenize,\n
["'_id': 'hi', 'contents':'ho'}",\n
{decoder,unicode,null,1,2,key}]},\n {cjson,decode_object,3},\n
{cjson,json_decode,2},\n
{couch_httpd,handle_doc_request,5},\n
{couch_httpd,handle_request,2},\n {mochiweb_http,headers,4},\n
{proc_lib,init_p,5}]}'))

@djc
Copy link
Owner Author

djc commented Jul 12, 2014

From cmlenz on November 05, 2008 13:52:52

The document needs to be a dict, not a JSON string. (I may need to add a check for this).

Also, when you use the item assignment syntax (instead of the create method), you must leave out the _id
member.

So:

f = db['hi'] = {'contents': 'ho'}

@djc
Copy link
Owner Author

djc commented Jul 12, 2014

From wjh...@gmail.com on November 06, 2008 06:28:50

Fabtabulous!
Thanks so much! I think a check on a string input would be good but clearly I was
just doing it wrong! Also it makes sense I should have left off the "_id" part I
think I must have tried it from a .create() sample where I was trying to get the name
set.

Thanks again for build this library! I like couchdb but all the REST URLs are
confounding to me (especially when getting into views!).

@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