-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Couchbase Essentials
By :

The real power of composite keys isn't the ability to search in multiple fields, but the ability to perform grouping with aggregation. To illustrate this point, we'll revisit the blog post document with a new property for published date:
{ "title": "Composite Keys with Couchbase Views ", "body": "Composite keys are arrays...", "publishedDate": "2014-09-17", "type": "post" }
Let's imagine that we want to display both a list of posts by year and month and the count of posts by year and month. By writing a view that uses compound keys and grouping methods, we are able to achieve both. Starting with the map function, we'll emit the year and month as values in our composite (array) key:
function(doc, meta) { if (doc.type == "post" &&doc.publishedDate) { emit(dateToArray(doc.publishedDate), null); } }
As always, we first check the type of the document and verify that it contains a publishedDate
property. We then use the built-in dateToArray
function provided by...
Change the font size
Change margin width
Change background colour