Using REST to search CouchDB

Using REST to search CouchDB uses a view with a map to create your index, which you insert once, and then a GET HTTP request.

How to do it...

We can modify the previous doGet function to search for a particular call sign, like this:

function doGet(call) { $.ajax({ type: "GET", url: "http://localhost:5984/documents/_design/stations/_view/byCall" + (call != null & call != '') ? ( '?key=' + call ) : '' ), dataType:"json", }) .done(function(result) { $('#json').html(JSON.stringify(result)); var resultHtml = '<table><tr><td><b>id</b></td>'; resultHtml += '<td><b>revision</b></td><td><b>call</b></td>'; resultHtml += '<td><b>lat</b></td><td><b>lng</b></td></tr>'; for(var i = 0; i < result.rows.length; i++) { var item = result.rows[i] ...

Get JavaScript JSON Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.