【发布时间】:2016-11-28 20:07:53
【问题描述】:
我遇到了一些设计问题。
假设我有两个收藏:
Colletion A stores apples ( _id , appleName )
Collection B stores apple votes ( _id , apple_id , enum(0,1) )
然后我想返回集合 A,并根据 apple_id 减少集合 B,以将 0 到 1 的值作为主对象上的属性返回。 (比如乐谱)
示例数据:
集合一个数组
[{_id : 1, appleName : 'grannySmith'},{_id : 2, appleName : 'greenApple'},{_id : 3, appleName : 'anotherApple'}]
集合 B 数组
[{_id : 1, appleId : 1, vote : 0}, {_id : 2, appleId : 1, vote : 1}, {_id : 3, appleId : 1, vote : 1}]
从此我正在寻找集合 A 以减少 B 返回
collection 一个带有 reduce 的数组
[{_id : 1, appleName : 'grannySmith', score : 2},{_id : 2, appleName : 'greenApple'},{_id : 3, appleName : 'anotherApple'}]
看到它现在从带有链接 ID 的集合 B 的减少中得到 2 分
【问题讨论】:
-
您应该包括一些示例数据和基于这些数据的预期结果
-
@Khang 干杯,刚刚添加了一些。
标签: javascript mongodb meteor