2014-09-25 61 views
2

我的文檔rethinkdb - 如何做窩`group`查詢

{ 
    itemName: 'name1', 
    itemType: 'book', 
    createTime: '2014-09-24 10:10:10' 
} 

然後我想通過createTimeitemType

換句話說查詢最後n天創建的項目組,我期望我的結果像這樣

[{ 
    group: '2014-09-24', 
    reduction { 
     { 
     group: 'book', 
     reduction: {count: 100} 
     }, 
     { 
     group: 'computer', 
     reduction: {count: 100} 
     }, 
    }, 
    { 
    group: '2014-09-22', 
    reduction { 
     { 
     group: 'book', 
     reduction: {count: 100} 
     }, 
     { 
     group: 'computer', 
     reduction: {count: 100} 
     } 
    } 
}] 

的RQL 5月看起來像

r.db(xx).table(yy) 
.order({index: r.desc(createTime)}) 
.group(r.row('createTime').date()) 
.map(function() { 
    ???? 
}).ungroup() 

回答

3

您也可以直接訂購的一切(但你沒有得到嵌套字段:

r.db(xx).table(yy) 
    .group([r.row("createTime"), r.row("itemType")]) 
    .count() 

你不知何故不能使用groupgroup現在。 請參閱https://github.com/rethinkdb/rethinkdb/issues/3097以跟蹤此限制的進度。