O'Reilly logo

JavaScript JSON Cookbook by Ray Rischpater

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Setting up a data view in CouchDB with Node.js and Cradle

You can query CouchDB for documents by their ID, but of course, most of the time, you'll want to issue more complex queries, such as matching a field in a record against a particular value. CouchDB lets you define views of your data that consist of an arbitrary key in a collection of objects and then the objects derived from the view. When you specify a view, you're specifying two JavaScript functions: a map function that maps keys to items in your collection, and then an optional reduce function that iterates over the keys and values to create a final collection. In this recipe, we'll use the map function of a view to create an index of records by a single field.

How to do it...

Here's how ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required