Closed GoogleCodeExporter closed 8 years ago
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.
Original comment by cmlenz
on 5 Nov 2008 at 5:02
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 "<stdin>", line 1, in <module>
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}]}'))
>>>
Original comment by wjh...@gmail.com
on 5 Nov 2008 at 6:26
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'}
Original comment by cmlenz
on 5 Nov 2008 at 9:52
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!).
Original comment by wjh...@gmail.com
on 6 Nov 2008 at 2:28
Original issue reported on code.google.com by
wjh...@gmail.com
on 14 Oct 2008 at 1:25