Reputation: 653
I have some doubt regarding the key value storage in couchbase. Normally we store data as document. I have some questions.
what is the benefit of storing as key-value?
{
"name":"xxx",
"age":"yyy"
}
How ican i store this document as key value.
Upvotes: 1
Views: 1724
Reputation: 5333
A document type in Couchbase means that the value is in json form. A key-value type just means that the value is a blob and Couchbase won't be able to interpret the data for some of its features. For example, if you store a value in non-json (eg. key-value) form then it is not indexable.
In Couchbase, every piece of data is stored in key-value form, but if the value is in json form then the value contains a document.
Storing data in key value form makes sharding data very easy to do. All NoSQL databases have some form of auto-sharding mechanism built in to them and the reason that they are efficient is because of the key-value nature of the data they contain.
In one of the Couchbase SDKs there should be a set API. The API usually looks something like this set(String key, Object value). You should fill out this function something like this set("my_key", "{\"name\":\"xxx\",\"age":\"yyy"}". To retrieve the document use the key.
Upvotes: 4