Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7086443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:33:00+00:00 2026-05-28T07:33:00+00:00

I am looking for a way to insert a document into a CouchDB database

  • 0

I am looking for a way to insert a document into a CouchDB database using Mathematica.
Based on this post, I tried it using the following code:

InsertDocument[key_, value_] := 
With[{url = 
  "http://couchdburl/database/"},
Import[url, "XML", "RequestMethod" -> "POST", 
 "RequestParameters" -> {"key" -> key, "value" -> value}]]

But when I try to execute it like this, for instance:

InsertDocument[110, 1]

I get the following error:

Import::erropts: The value {key->110,value->1} specified for the option RequestParameters is invalid. >>

Edit:

Following kguler’s comment, I converted the parameters to string, and the previous error disappeared.
I have also fixed the forgotten } in my code sample, and removed the concatenation of the url with the key parameter.
Now I’m experiencing a different error:

Throw::nocatch: Uncaught Throw[Null,UtilitiesURLToolsPrivateURLTOOLSException[UtilitiesURLToolsPrivateBADCONNECTION,http://couchdburl/database/%5D%5D returned to top level. >>

I tried to make a request using curl to the couchDb url, using a dummy document:

curl -X POST http://couchdburl/database/ -H "Content-Type: application/json" -d {}

and the response was as expected:

{“ok”:true,”id”:”57291ccea74c455beb2d7a37fe001624″,”rev”:”1-967a00dff5e02add41819138abb3284d”}

Am I still missing any option that should be used in the Import function?
Maybe some option to set the content-type as application/json?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:33:01+00:00Added an answer on May 28, 2026 at 7:33 am

    I managed to do it following the same idea as presented in this SO question.

    After some problems, the following code worked:

    << JLink`
    
    client = JavaNew["org.apache.commons.httpclient.HttpClient"];
    
    method = JavaNew["org.apache.commons.httpclient.methods.PostMethod", 
       "http://couchdburl/database/"];
    
    method@setRequestHeader["Content-Type", "application/json"];
    
    entity = 
     JavaNew["org.apache.commons.httpclient.methods.StringRequestEntity", 
      "{\"key\":\"10\",\"value\":\"0\"}", "application/json", Null]
    
    method@setRequestEntity[entity]
    
    client@executeMethod[method]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im looking for the appropriate way to insert date into one table based on
I'm hand-maintaining an HTML document, and I'm looking for a way to automatically insert
I'm looking for a way to insert a <style> tag into an HTML page
I am looking for a way to insert javascript code block to end of
I'm looking for a way to map a simple insert stored procedure using NHibernate
I'm looking for the way to insert a line of code with a keystroke
Looking for a way to programmatically insert comments (using the comments feature in Word)
I'm looking for a way to insert royalty (or otherwise) free photos quickly into
I'm looking for a way to insert checkbox fields into an email, so when
I am looking for a way to insert code comment blocks semi-automatically in all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.