How to choose an adequate way to get data from Couchbase


Hi, all
I am new to couchbase and have some questions with getting data from couchbase.
There are many way to get data like

  1. Retrieving documents

JsonDocument walter = bucket.get(“walter”);
System.out.println("Found: " + walter);

  1. Working with views

  2. Working with N1QL

  3. another way(I’m not sure)?

Does any one can give me a simple explanation when to use those ways in specific situation?

I’m confused on using which way to retrieve data(specific situation for specific way).

I’m working on Java SDK.


You’ve pretty much listed all the APIs. Typical use-cases for each API would be:

  • Key-Value - Use when you already know the key of the document(s) you are interested in. Typically the fastest access method.
  • Map/Reduce - Used for pre-defined views on your data, where there’s small number of common ways you want o view your data; as each view needs to be pre-defined on the cluster.
  • N1QL - Used for ad-hoc queries. Queries can be dynamic, only requires indexes to be pre-defined.
1 Like

Thanks for your explanation.
When it comes to query a data with some conditions(ex. students who belongs to class A), which way is better in performance?
Using N1QL(WHERE class = ‘A’ ) or using another way to get the doc ID list and then retrieve it with Key-Value(bucket.get…)?