0

I am trying to create a new document in a couchDB database but with the following code I get a '400 bad request' response. I want to create a document that does not contain any other information than the _id (and of course the generated _rev).

            var xhrCreate = new XMLHttpRequest();
            xhrCreate.open('PUT','http://domainName:5984/dbName/docName/', true);
            xhrCreate.setRequestHeader("Content-type", "application/json");
            xhrCreate.send();

The CouchDb documentation says that a 400 error indicates a:

"Bad request structure. The error can indicate an error with the request URL, path or headers. Differences in the supplied MD5 hash and content also trigger this error, as this may indicate message corruption."

Could anyone point me in the right direction? Hints and help is much appreciated.

3
  • remove the trailing slash from the URL and try adding an empty document in the send rather than nothing: "{}". Commented Feb 11, 2013 at 20:51
  • Thanks :) Sending an empty document worked! Really appreciate your help and have a nice day. Commented Feb 12, 2013 at 9:36
  • I'll post it as an answer. Glad it worked for you. Commented Feb 12, 2013 at 11:40

1 Answer 1

2

CouchDB requires an empty document as part of the content:

xhrCreate.send('{}');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.