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.
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());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With