Chapter 6. Finding Your Data with Views
Views are useful for many purposes:
Filtering the documents in your database to find those relevant to a particular process.
Extracting data from your documents and presenting it in a specific order.
Building efficient indexes to find documents by any value or structure that resides in them.
Use these indexes to represent relationships among documents.
Finally, with views you can make all sorts of calculations on the data in your documents. For example, a view can answer the question of what your company’s spending was in the last week, month, or year.
What Is a View?
Let’s go through the different use cases. First is extracting data that you might need for a special purpose in a specific order. For a front page, we want a list of blog post titles sorted by date. We’ll work with a set of example documents as we walk through how views work:
{"_id":"biking","_rev":"AE19EBC7654","title":"Biking","body":"My biggest hobby is mountainbiking. The other day...","date":"2009/01/30 18:04:11"}{"_id":"bought-a-cat","_rev":"4A3BBEE711","title":"Bought a Cat","body":"I went to the the pet store earlier and brought home a little kitty...","date":"2009/02/17 21:13:39"}{"_id":"hello-world","_rev":"43FBA4E7AB","title":"Hello World","body":"Well hello and welcome to my new blog...","date":"2009/01/15 15:52:20"}
Three will do for the example. Note that the documents are sorted by
"_id", which is how they are stored in the database. Now we define a ...