Couchbase : How to access and change the document of size more than 2.5Kb.


We faced a situation were we have to firstly see the data and then change it accordingly in couchbase, but the GUI of couchbase doesn’t allows us to see the data of size more than 2.5kb and forget about changing,


Screenshot from 2015-08-07 12:36:16

So there is a quick hack of how you can actually change the data without using the GUI and just by making a curl request:

If you want to see the data :

Just make this CURL request

curl -X GET -H "Content-Type: application/text" "http://Administrator:<password>@<server address>:<port number>/pools/default/buckets/<bucket-name>/docs/<doc-id>"

Example:

curl -X GET -H "Content-Type: application/text" "http://Administrator:123456@localhost:8091/pools/default/buckets/user/docs/shivansh"

And you’ll get a response like this :

{"meta":{"id":"shivansh","rev":"4-13f81d12a58600000000000000000000","expiration":0,"flags":0},"json"</code><code class="wrappedText focusRow">:{"click":"Shivansh","new in 2.0":"there are no reserved field names"}}

And inside the field json you’ get your required Json,

You can easily do this just by seeing developer console.. šŸ˜‰

Now the big task i.e. If you want to change the data

So for that firstly retrieve the data from above request make changes, and then make a POST request to the same url with the new Json. It will get updated.

Example:

curl -X POST -H "Content-Type: application/text"
"http://Administrator:12345@localhost:8091/pools/default/buckets/user/docs/shivansh" -d'{"name": "Shivansh", "last name": "Srivastava"}

And it will automatically update the required document.

About shiv4nsh

Coder, Gamer, Learner..!!
This entry was posted in Scala and tagged , , , . Bookmark the permalink.