public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException { Session s = new Session(getServletContext().getInitParameter("couchdb"), 5984); Database db = s.getDatabase("testdb"); ViewResults results = db.getAllDocuments(); PrintWriter out = res.getWriter(); res.setContentType("text/plain"); // Header out.println("index,id"); @SuppressWarnings("unchecked") List<JSONObject> rows = (List<JSONObject>) results.get("rows"); int i = 0; for (JSONObject doc : rows) { String line = i + "," + doc.getString("id"); out.println(line); i++; if (i % 100 == 0) { out.flush(); } } out.close(); }