vendredi 6 mars 2015

Get the count of items in subcategories


Vote count:

0




There is a tree of categories, such as



Mammalia-Rodentia...,
...,
Mammalia-Primates-Hominidae...,
Mammalia-Primates-Lemuridae...,
...
etc.


There is a set of categorized beings.


Given a category (e.g. Mammalia or Primates) how to calculate the number of beings in each subcategory:



{ Primates: 1098, Rodentia: 8932 }


or



{ Lemuridae: 129, Hominidae: 432 }


I'm trying to model Beings like this:



{
name: "being #1",
categories: [...,'Lemuridae', 'Primates', 'Mammalia']
}


To aggregate for e.g. Primates I {$match : {categories:'Primates'}} then I nees $project a category just before 'Primates' and it looks like this is impossible within aggregation framework... Thus either the model is incorrect or I have to use mapreduce...


Any Ideas?



asked 37 secs ago







Get the count of items in subcategories

Aucun commentaire:

Enregistrer un commentaire