user1697575
user1697575

Reputation: 2848

CouchbaseClient how to get list of all DesignDocuments in the bucket

I'm trying programmatically retrieve list of all design documents in the given bucket via CouchbaseClient. I have followed creating-views-from-sdk documentation but its only explains how to create view. What I need it a way to retrieve all design documents and their views. Any solution out there?

So far I was able to get only one design document...but the name is not coming from the server, e.g.

CouchbaseClient client = new CouchbaseClient(urls, bucketName, bucketPassword);

DesignDocument dc = client.getDesignDocument("MY-HARDCODED-DOC-NAME");

List<View> views = (List<View>) dc.getViews();
for (View view : views)
{
  // process view data
}

What I'm trying to accomplish is to write an utility to import/export views from a given couchbase bucket. Since, strangely enough this basic function can't be found anywhere in the admin tools that come with couchbase.

Upvotes: 1

Views: 1471

Answers (1)

cmbaxter
cmbaxter

Reputation: 35443

I don't think you can do this with the java client, but there is an endpoint you can hit with an HTTP client from java to get this info:

http://localhost:8091/pools/default/buckets/mybucketname/ddocs

Just replace mybucketname with the bucket you want to get ddocs for. You will need to supply the basic auth header to hit this endpoint so be sure to not forget that part. You will get back json that you can then parse to get the names of the ddocs in the bucket.

Upvotes: 3

Related Questions