Retrieving data from CouchDB with Cradle
CouchDB doesn't use the same query paradigm that MySQL and MongoDB subscribe to. Instead, it uses a precreated view to retrieve the desired data.
In this example, we'll use Cradle to obtain an array of quotes according to the specified author, outputting our quotes to the console.
Getting ready
As in the previous recipe, Storing data to CouchDB with Cradle, we'll need CouchDB installed on our system along with cradle
. We can also take the quotes.js
file from that recipe and place it in a new directory.
How to do it…
We're working on the quotes.js
file from the previous recipe where we called checkAndSave
if our database existed or we called it from the callback of db.create
if it didn't exist. Let's modify checkAndSave
slightly as shown in the following code:
function checkAndSave(err) { errorHandler(err); if (params.author && params.quote) { db.save({author: params.author, quote: params.quote}, outputQuotes); return; } outputQuotes...