var listsView = database.viewNamed("listsView")
listsView.setMapBlock({ (doc, emit) -> Void in
if doc["type"] as? String == "list" {
emit(doc["date"], nil)
}
}, version: "1")
And Item documents have a "list" property that contains the documentID of the list that contains it.
All this works well.
But now in the viewcontroller that displays all the Lists, for each List, I would like to display the number of Items that are associated with it.
Is there any way that I can modify my view so that it serves both to filter list-type documents and keep track of the number of list-items in it?
Thx in advance,
On Jan 8, 2015, at 12:24 PM, Sebastien ARBOGAST <sebastien...@gmail.com> wrote:
But now in the viewcontroller that displays all the Lists, for each List, I would like to display the number of Items that are associated with it.
--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/1A9405E3-B6CA-4C4B-8ED1-AC89D011CABA%40couchbase.com.
On Jan 8, 2015, at 1:52 PM, Sebastien ARBOGAST <sebastien...@gmail.com> wrote:Is it possible to get a list of list IDs and number of items in each list, the number being 0 if there is no item associated with this list?
var listsView = database.viewNamed("listsView")
listsView.setMapBlock({ (doc:[NSObject : AnyObject]!, emit) -> Void in
switch doc["type"] as String {
case "list": emit(doc["_id"], doc["date"])
case "item": emit(doc["list"], "")
default: return
}
}, reduceBlock: { (keys:[AnyObject]!, values:[AnyObject]!, rereduce:Bool) -> AnyObject! in
var date:AnyObject = values.filter({ (x) -> Bool in
return x as? String != ""
})[0]
return [date, values.count - 1]
}, version: "1")
Now I don't want to ask for too much, but is there any way that I can sort the results by list date, or do I have to do this manually after I get the query result?
--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/59E9EA0D-A3E8-4CE5-B832-C545AF3C3880%40couchbase.com.
On Jan 8, 2015, at 2:53 PM, Sebastien ARBOGAST <sebastien...@gmail.com> wrote:Now I don't want to ask for too much, but is there any way that I can sort the results by list date, or do I have to do this manually after I get the query result?