我有一個記錄數很少的mongodb集合。 我想迭代我的集合中的記錄並返回一個customObject。 對於每條記錄,我想對它進行一些計算,並相應地在我的customObject中包含一個條目,如果它符合我的條件,然後最終返回customObject。迭代mongo db中的記錄並返回自定義對象
我使用mongoose.js
做它說我的紀錄是
Friends:{
{name:"John", money_lent:100},
{name:"Tom", money_lent:100}
{name:"Tom", money_lent:100}
{name:"Jill", money_lent:100}
{name:"John", money_lent:100}
{name:"Nate", money_lent:100}
{name:"John", money_lent:100}
{name:"Jill", money_lent:100}
{name:"Nate", money_lent:100}
{name:"Nate", money_lent:100}
{name:"Nate", money_lent:100}
{name:"Rob", money_lent:100}
}
我想計算和對象等,並返回我的控制器使用
{
{name:"John", times_money_lent:2}
{name:"Tom", times_money_lent:2}
{name:"Jill", times_money_lent:2}
{name:"Nate", times_money_lent:4}
{name:"Rob", times_money_lent:1}
}
記錄都保存在MongoDB中 –
是啊,但你說你用貓鼬來檢索他們,所以他們現在在你的JavaScript代碼,對不對? – tjb1982