Querying Data with Mapreduce Views

Different databases offer different ways of querying data, but most include some concept of indexing. When you index data in a database, you make it available for quick retrieval by some field or attribute of the data.

With CouchDB, you write mapreduce functions, which produce views. A view is a kind of index that maps values back to documents. With a view, you can query for documents with particular attributes or fields—like finding a book by its author.

We’ll create two views for our Gutenberg data set: one for finding books by author, and one for finding books on a given subject. Since CouchDB views consist of JavaScript code, we’ll keep them in a Node.js module and write a small utility program for ...

Get Node.js the Right Way 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.