If we want to include a list view that displays only tasks that are not yet marked as complete, we'll need to modify our view to incorporate this change. The following snippet shows this modification. The action and view for the corresponding list page differ only in the name of the Couchbase view queried by the client (for example, all_incomplete
and all
):
//view named "all_incomplete" in the "tasks" design document function(doc, meta) { if (doc.type == "task" && doc.isComplete === false) { emit(null, null); } }
Notice that the check for incomplete status explicitly uses JavaScript's ===
operator. If you haven't used this operator, you should now know that it performs an explicit type check along with a value check. The reason to use it here is that ! doc.isComplete
would return false
if the property is undefined (which might be acceptable in this particular case, but not in most other cases).
Alternatively, we can create a view where the isComplete...