Including Documents

Let’s get all of our book titles, including the original documents, in the results this time:

curl -X GET http://localhost:5984/books/_design/default/_view/titles -G \
-d reduce=false \
-d include_docs=true

The response:

{
   "total_rows":4,
   "offset":0,
   "rows":[
      {
         "id":"978-0-596-80579-1",
         "key":"Building iPhone Apps with HTML, CSS, and JavaScript",
         "value":192,
         "doc":{
            "_id":"978-0-596-80579-1",
            "_rev":"1-09ce09fef75068834da99957c7b14cf2",
            "title":"Building iPhone Apps with HTML, CSS, and JavaScript",
            "subtitle":"Making App Store Apps Without Objective-C or Cocoa",
            "authors":[
               "Jonathan Stark"
            ],
            "publisher":"O'Reilly Media",
            "formats":[
               "Print",
               "Ebook",
               "Safari Books Online"
            ],
            "released":"2010-01-08",
            "pages":192
         }
      },
      {
         "id":"978-0-596-15589-6",
         "key":"CouchDB: The Definitive Guide",
         "value":272,
         "doc":{
            "_id":"978-0-596-15589-6",
            "_rev":"2-099d205cbb59d989700ad7692cbb3e66",
            "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,
            "formats":[
               "Print",
               "Ebook",
               "Safari Books Online"
            ]
         }
      },
      {
         "id":"978-1-565-92580-9",
         "key":"DocBook: The Definitive Guide",
         "value":648,
         "doc":{
            "_id":"978-1-565-92580-9",
            "_rev":"1-b945cb4799a1ccdd1689eae0e44124f1",
            "title":"DocBook: The Definitive Guide",
            "authors":[
               "Norman Walsh",
               "Leonard Muellner"
            ],
            "publisher":"O'Reilly Media",
            "formats":[
               "Print"
            ],
            "released":"1999-10-28",
            "pages":648
         }
      },
      {
         "id":"978-0-596-52926-0",
         "key":"RESTful Web Services",
         "value":448,
         "doc":{
            "_id":"978-0-596-52926-0",
            "_rev":"2-de467b329baf6259e791b830cc950ece",
            "title":"RESTful Web Services",
            "subtitle":"Web services for the real world",
            "authors":[
               "Leonard Richardson",
               "Sam Ruby"
            ],
            "publisher":"O'Reilly Media",
            "released":"2007-05-08",
            "pages":448,
            "formats":[
               "Print",
               "Ebook",
               "Safari Books Online"
            ]
         }
      }
   ]
}

See Table 4-15 for the rows in tabular format.

Table 4-15. Rows from the titles view

keyidvaluedoc (truncated)
"Building iPhone Apps with HTML, CSS, and JavaScript""978-0-596-80579-1"192{…}
"CouchDB: The Definitive Guide""978-0-596-15589-6"272{…}
"DocBook: The Definitive Guide""978-1-565-92580-9"648{…}
"RESTful Web Services""978-0-596-52926-0"448{…}

Note

Including documents is a very convenient feature. However, you may want to consider retrieving the documents separately. This may seem less efficient, but it gives your client the opportunity to cache individual documents. If your client has a cached version, it can make a conditional HTTP request using the cached document’s ETag. If the ETag matches that of the most current revision of the document, CouchDB will respond indicating that the document has not been modified and will not send the full document. This can save bandwidth and speed up requests.

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.