How to find all documents in couchDB using ektrop library

901 Views Asked by At

I have gone through all the blogs available for the ektrop library and also the source code of the library.I have found that get(class obj,String id) function is available but If I use this function then only one document will be returned according to the id given.So I want to read all the changed documents present in the bucket.How Can I achieve this.Thanks in advance any help would be appreciable.

2

There are 2 best solutions below

2
Lalit Kushwah On

Hello all I have got the answer the question asked by me above.Here is the steps by which you can get the all documents or simply the result of _changes API is used.

  1. Integrate the Ektorp library into your project.
  2. Use the follwing code to get the all document.

                 HttpClient httpClient = new StdHttpClient.Builder()
                .url("http://localhost:5984/")
                .build();
        CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
        CouchDbConnector db = new StdCouchDbConnector("my_database", dbInstance);
        ChangesCommand.Builder builder = new ChangesCommand.Builder();
        ChangesCommand changesCommand =builder.build() ;
        List<DocumentChange> documentChangeList=db.changes(changesCommand);
    
        for(int i=0;i<documentChangeList.size()-1;i++) {
            System.out.println(documentChangeList.get(i).getId());
        }
    
0
Alexis Côté On

You are probably looking for the _all_docs endpoint.

ViewQuery q = new ViewQuery().allDocs().includeDocs(true);

List<Sofa> bulkLoaded = db.queryView(q, Sofa.class);

You can find more detailed information in the api