我有三种文档类型MainCategory,Category,SubCategory ...每个都有一个与其父文档的id相关的parentid。
所以我想设置一个视图,这样我就可以得到一个位于MainCategory下的SubCategory列表(最好只使用一个map函数)...我还没有找到一种方法来安排视图所以这是可能的。
我目前已经设置了一个获得以下输出的视图 -
{"total_rows":16,"offset":0,"rows":[
{"id":"11098","key":["22056",0,"11098"],"value":"MainCat...."},
{"id":"11098","key":["22056",1,"11098"],"value":"Cat...."},
{"id":"33610","key":["22056",2,"null"],"value":"SubCat...."},
{"id":"33989","key":["22056",2,"null"],"value":"SubCat...."},
{"id":"11810","key":["22245",0,"11810"],"value":"MainCat...."},
{"id":"11810","key":["22245",1,"11810"],"value":"Cat...."},
{"id":"33106","key":["22245",2,"null"],"value":"SubCat...."},
{"id":"33321","key":["22245",2,"null"],"value":"SubCat...."},
{"id":"11098","key":["22479",0,"11098"],"value":"MainCat...."},
{"id":"11098","key":["22479",1,"11098"],"value":"Cat...."},
{"id":"11810","key":["22945",0,"11810"],"value":"MainCat...."},
{"id":"11810","key":["22945",1,"11810"],"value":"Cat...."},
{"id":"33123","key":["22945",2,"null"],"value":"SubCat...."},
{"id":"33453","key":["22945",2,"null"],"value":"SubCat...."},
{"id":"33667","key":["22945",2,"null"],"value":"SubCat...."},
{"id":"33987","key":["22945",2,"null"],"value":"SubCat...."}
]}
我将使用哪些QueryString参数来说出具有以[“22945”开头的键的行....当我所有的(在查询时)是id“11810”(在查询时我不喜欢我不知道id“22945”。
如果有任何意义。
由于
答案 0 :(得分:1)
存储类别的方式对于您尝试对其执行的查询来说似乎不是最理想的。
MongoDB.org在various strategies to implement tree-structures上有一个页面(它们也应该适用于Couch和其他doc dbs) - 你应该考虑Array of Ancestors
,你总是存储节点的完整路径。这使得更新/移动类别更加困难,但查询很容易且快速。