Object {_id: "9g9ySxozSWn1", name: "test1", price: 1}
Object {_id: "9g9ySxozSWn2", name: "test2", price: 2}
Object {_id: "9g9ySxozSWn3", name: "test3", price: 3}
Object {_id: "9g9ySxozSWn4", name: "test3", price: 6}
Object {_id: "9g9ySxozSWn5", name: "test3", price: 3}
什麼是總結了所有的價格其中,例如名稱是TEST3最好的方法是什麼?
我喜歡這個!謝謝! – 2014-04-11 16:57:58
[foreach](http://docs.meteor.com/#foreach)也適用於這種情況。 – 2014-04-11 17:12:01
有兩件事:1)流星的'.find()'返回一個遊標,所以最好在Akshat的答案中執行'.find()。fetch()'。 2)這是濫用'map',最好使用'forEach'。或甚至更好:'total = MyCollect.find({name:'test3'})。fetch()。map(item => item.price).reduce((a,b)=> a + b)' – ffxsam 2016-03-28 01:22:53