0
我試圖獲得Mongodb的掛件,現在,我有一個只有幾百條記錄的非常小的集合,我想從中動態更新一些字段與JavaScript。但是,儘管現在文檔太少,但下面的查詢和更新至少需要24秒。我認爲一旦我們投入生產並且有大量文件需要更新,我認爲這對我沒有任何用處。任何人都可以幫我解決下面我的代碼有什麼問題?Mongodb查詢花費時間過長
在此先感謝
var d = new Date();
var sapm = 1.8;
i = 0;
db.getCollection('content').find().forEach(function(x) {
var window = (d - x.updated_at)/(24 * 60 * 60 * 1000);
var feed = db.content.find({}, {
_id: x._id
});
var comment = x.total_comment || 0;
var up = x.total_up || 0;
var interaction = up + (comment/2);
var hourage = (d - (x.updated_at));
var rank = interaction/Math.pow((hourage - 4) * sapm);
if (window <= 15) {
db.content.update({
'_id': x._id
}, {
$set: {
"rank": rank,
}
}, {
multi: true
});
}
});
非常感謝。我現在不能投票,但你爲我節省了很多麻煩。 – plpc
我已經添加了這個答案 – Alex