7

I am totally new in couchbase. I am using the java api and i want somehow to view all available keys in a bucket. Is this possible? Thanks in advance.

stelios.p
  • 177
  • 4
  • 10
  • Mayer06, you might be right, but have in mind, that not all people are devs, that can grasp easy all the info.For example, i am a qa engineer.I use dev tools and i code, but due to my nature of my work, i cannot always go as deep, as you probably can. – stelios.p Jan 12 '14 at 08:54
  • 1
    Agreed, no problem there - but StackOverflow questions are supposed to show a little bit of effort on your part :) – theMayer Jan 12 '14 at 13:03

1 Answers1

11

It is possible but you will need to create a view to do this (secondary index).

You can create a view in the couchbase webconsole like so:

function (doc, meta) {
  if(meta.type == "json") {
     emit(null);
  }
}

This will emit all the keys (keys are automatically emitted anyway so no need to include anything extra).

Then you can query the view like below using the java sdk. (Obviously you need to instantiate the couchbase client etc)

View view = couchbaseClient.getView("DESIGN_VIEW NAME", "VIEW_NAME");
Query query = new Query();
ViewResponse viewResponse = couchbaseClient.query(view, query);

List<String> keys = new ArrayList<String>();
for (ViewRow viewRow : viewResponse) {
   keys.add(viewRow.getKey());
}
DaveR
  • 9,540
  • 3
  • 39
  • 58
scalabilitysolved
  • 2,473
  • 1
  • 26
  • 31