Book Image

Couchbase Essentials

Book Image

Couchbase Essentials

Overview of this book

Table of Contents (15 chapters)
Couchbase Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Listing tasks


In the preceding snippet, after the task is created, a redirect to an index page is performed. This page is a list page used to view tasks. Building a list page requires finding all our tasks that will require a slight change to our model:

public class Task
{
  public string Description { get; set; }
  public bool IsComplete { get; set; }
  public bool Type { get { return "task"; }
}

Recall our discussion from the previous chapters on the use of a type property on documents to provide a classification for related documents, much in the way a table does for relational databases. In our to-do application, to identify tasks, we'll add a type property (which is read-only). The property is set to the task string, which will ensure that all task documents are serialized with this type. With this addition, we're ready to write our list page, starting with a map function:

//view named "all" in a design doc "tasks"
function(doc, meta) {
  if (doc.type == "task") {
    emit(null, null)...