Arun M R Nair
Arun M R Nair

Reputation: 653

Difference between document type and key values type in couchbase

I have some doubt regarding the key value storage in couchbase. Normally we store data as document. I have some questions.

  1. What is the difference between document type and key-value type?
  2. How can i achieve couchbase key - value storage in java ? Can you explain with a small example.
  3. 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

Answers (1)

mikewied
mikewied

Reputation: 5333

  1. 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.

  2. 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.

  3. 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.

  4. 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

Related Questions