0

I am a newbie in Couchbase Mobile , i am trying to add this json string like shown below in db but couldn't way to this . By adding i meant creating a document based out of this json and then add this document to db .

{
  "array": [
    1,
    2,
    3
  ],
  "boolean": true,
  "null": null,
  "number": 123,
  "object": {
    "a": "b",
    "c": "d",
    "e": "f"
  },
  "string": "Hello World"
}
Code_Life
  • 5,742
  • 4
  • 29
  • 49

1 Answers1

0

CouchDB stores documents which are represented in json. To add your json string to the document, add an "_id" attribute that has a string as the name of the document. I will call this document "my_json" for this example.

Then use whatever http library you have (I will use the curl utility) to POST the json to the database.

curl -X POST -H "Content-Type: application/json" -d '{"_id": "my_json", "array":[1,2,3], "boolean": true, "null": null,"number": 123, "object": {"a": "b","c": "d", "e": "f"},"string": "Hello World"}' "http://localhost:5984/example"

This will create a doc called "my_json" that is in the "example" database in the server running on localhost port 5984.

You should then get a response from the server that looks something like this:

{"ok":true,"id":"my_json","rev":"1-03c9094bea172b21e23502b82cc6e7ca"}

(Your "rev" number will be different.)

For more information on the http api for CouchDB see the docs or the getting started page.

  • Thanks for the reply but this wouldn't work for me as my couchdb is inside my Android App and i hve no place to run this command also . – Code_Life Jan 10 '15 at 07:38