I'm getting an error on one part of the :clouchdb
example code (that's a link, but the examples.lisp
file included doesn't work properly either).
Specifically, when I input
> (create-document '((:|name| . "wine") (:|tags| . ("beverage" "fun" "alcoholic"))))
I get a DOC-ERROR
condition
Reason "Content-Type must be application/json", Document ID: "NIL"
[Condition of type DOC-ERROR]
Restarts:
0: [RETRY] Retry SLIME REPL evaluation request.
1: [*ABORT] Return to SLIME's top level.
2: [TERMINATE-THREAD] Terminate this thread (#<THREAD "repl-thread" RUNNING {10040D2E11}>)
Backtrace:
0: (POST-DOCUMENT ((:|name| . "wine") (:|tags| "beverage" "fun" "alcoholic")))
1: (SB-INT:SIMPLE-EVAL-IN-LEXENV (CREATE-DOCUMENT '((:|name| . "wine") (:|tags| "beverage" "fun" "alcoholic"))) #<NULL-LEXENV>)
--more--
The intended effect of the example is to have CouchDB assign an ID to the new document (this is made clear both in the linked page and in the comments of the code file).
I'm running SBCL 1.0.40.0, clouchdb_0.0.11 (straight out of quicklisp) and CouchDB 0.11 from the Debian repos, in case it开发者_如何学C matters. I'm also on a 64-bit Debian box.
Can anyone point me in the right direction?
CouchDB requires a "Content-Type: application/json" when POST'ing documents, this is a fairly new requirement so I think clouchdb simply isn't doing it yet.
Shorter version: Sounds like clouchdb is not compatible with recent releases of CouchDB.
Just checked the source. Robert Newson above is correct; clouchdb
is still setting the content-type
to "text/javascript" while post
ing and put
ting documents (the latter seems to work anyway, only the post errors).
If you don't feel like using chillax as I suggest above, you can go into the clouchdb.lisp file and change the definition of post-document
such that it sets :content-type
to "application/json".
You should then be able to create-document
without an :id
set, and CouchDB will respond by generating a new one for you.
Patch based on the quicklisp
code for clouchdb
(not that this is complicated enough to need one):
--- clouchdb.lispOLD 2011-09-24 09:38:20.000000000 -0400
+++ clouchdb.lisp 2011-09-24 09:38:58.000000000 -0400
@@ -753,7 +753,7 @@
the :ID property."
(let ((res (ensure-db ()
(db-request (cat (url-encode (db-name *couchdb*)) "/")
- :content-type "text/javascript"
+ :content-type "application/json"
:external-format-out +utf-8+
:content-length nil
:method :post
精彩评论