couch4j Quick Start

Skip to end of metadata
Go to start of metadata

Quick Start

This is currently WIP.

5 minutes Quick start tutorial

Download the couch4j jar and the dependencies or add the couch4j dependency to your Maven pom.

The following code snippet shows the main building blocks of the couch4j library:

  • CouchDbClient - represents the client connection to the CouchDB server
  • Database - a single database
  • Document - the document stored in CouchDB
CouchDbClient client = new DefaultCouchDbClient(); // Reuse a single instance of CouchDbClient and Database
Database database = client.getDatabase("couch4j");

ViewResult allDocs = database.fetchAllDocuments();

System.out.format("Number of documents: %d%n", allDocs.getTotalRows());

for (ViewResultRow row : allDocs) {
    // Row
    System.out.println(row.getId());

    // Document
    Document doc = row.getDocument();
    System.out.println(doc.getId());
    System.out.println(doc.toJson());

    // OR

    // If the value of the row is an array
    JSONArray ary = row.getValueAsArray();

    // If it is an object
    JSONObject obj = row.getValueAsObject();
}

More

Labels

couch4j couch4j Delete
tutorial tutorial Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Anonymous replies:

You are not logged in. Any changes you make will be marked as anonymous. You may want to Log In if you already have an account. You can also Sign Up for a new account.