Map

In the Map step, input documents are transformed, or mapped, from their original structure into a new key/value pair. For example, if your input document represents a book and contains information about the book’s ISBN (the _id field in the following document), title, subtitle, authors, publisher, date released, and number of pages, then you may choose to map just the title. The result of this mapping for a single document would be the book’s title. We’ll use the following document representing a book in the examples in this chapter:

{
   "_id":"978-0-596-15589-6",
   "title":"CouchDB: The Definitive Guide",
   "subtitle":"Time to Relax",
   "authors":[
      "J. Chris Anderson",
      "Jan Lehnardt",
      "Noah Slater"
   ],
   "publisher":"O'Reilly Media",
   "released":"2010-01-19",
   "pages":272
}

Let’s create this document in our books database now. Using Futon:

  1. Navigate to http://localhost:5984/_utils/ using your web browser and click on the books database that you created earlier.

  2. From the “View” drop-down menu, select “All documents” if it is not already selected.

  3. Click “New Document”.

  4. Click on the “Fields” tab if it is not already active.

  5. Enter 978-0-596-15589-6 as the value of the _id field, and then click the “apply” button.

  6. Click on the “Source” tab.

  7. Double-click on the source and paste in the contents of the above document, replacing the existing source, and then click the “apply” button.

  8. Click “Save Document”. ...

Get Writing and Querying MapReduce Views in CouchDB 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.