2
시간 버킷을 사용하여 집계하려고합니다. 그런 다음 하루에 값이 가득 찬 배열을 반환하려고합니다 (문서가 없을 때 0). aggeagate 기능 작업 wondefully,이 같은 콜백 (이전 CONSOLE.LOG) 교체 할 때이지만 :RangeError : 최대 호출 스택 크기가 몽구스로 초과되었습니다.
Star.aggregate([{
$match: {
"mod": new mongoose.Types.ObjectId("53765a122c0cda28199df3f4"),
"time_bucket.month": new TimeBucket().month
}
},
{
$group: {
_id: "$time_bucket.day",
stars: {
"$sum": 1
}
}
},
{
$sort: {
'_id': 1
}
}],
function (err, mods) {
console.log(err, mods);
mods = mods.map(function (model) {
return model.toObject ? model.toObject() : model
});
var i, time, docs = [];
var hasGap = function (a, b) {
a = a.replace(/-/g, '');
b = b.replace(/-/g, '');
return a - b !== 1
}
var process = function (i, mods, docs) {
if (hasGap(mods[i]._id, mods[i + 1]._id)) {
docs.push(0);
return process(i, mods, docs)
}
docs.push(mods[i].stars);
return process(i + 1, mods, docs)
};
process(0, mods, docs);
console.log(docs);
});
를 내가 얻을 :
C:\Users\Me\Nodejs\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\base.js:245
throw message;
^
RangeError: Maximum call stack size exceeded
그리고 해결책? –
@Julien 업데이트 된 답변보기. OP의 데이터에 대해 더 알지 못하면 더 구체적으로 표현하기가 어렵습니다. – JohnnyHK