簡體   English   中英

MongoDB PHP findAndModify多種性能

[英]MongoDB PHP findAndModify Multiple Performance

我在名為Reports的集合中有一個要處理的文檔。 我做類似的查詢

$collectionReports->find(array('processed' => 0)) 

(介於50到2000個項目之間)。 我按照需要處理它們並將結果插入到另一個集合中,但是我需要更新原始報告以將處理設置為當前系統時間。 現在看起來像:

$reports = $collectionReports->find(array('processed' => 0));
$toUpdate = array();
foreach ($reports as $report) {
    //Perform the operations on them now
    $toUpdate = $report['_id'];
}
foreach ($toUpdate as $reportID) {
    $criteria = array('_id' => new MongoId($reportID));
    $data = array('$set' => array('processed' => round(microtime(true)*1000)));
    $collectionReports->findAndModify($criteria, $data);
}

我的問題是效率很低。 處理這些報告並將其插入到集合中可能需要700毫秒才能處理2000個報告,但是對於相同的2000個報告,僅更新處理時間至少需要1500毫秒。 有什么提示可以加快速度嗎? 提前致謝。

編輯:處理時間不必是確切的,它可以是腳本運行的時間(+/- 10秒左右),如果可以的話($ report)並更新時間就像這樣直接比在第一個foreach之后進行搜索要好。

感謝Sammaye,從findAndModify()更改為update()似乎更好,更快。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM