1万レコードのコレクションにデータを集計しています。 一致クエリはインデックスを使用します。最終結果のリストには3500件のレコードを含むカーソル時間の制限に影響なしaggrgate mongoDB
AggregateIterable<Document> aggregateIterable = timeCollection.aggregate(Arrays.asList(match, project,group)).batchSize(1000).allowDiskUse(true);
long curStartTs = Calendar.getInstance().getTimeInMillis();
MongoCursor<Document> cursor = aggregateIterable.iterator(); //this line roughly takes 15 seconds
long curEndTs = Calendar.getInstance().getTimeInMillis();
System.out.println("Cursor time - " + (curEndTs - curStartTs));
- 以下のコードを参照して下さい。最終結果のリストが今だけ30レコードが含まれている
Document limitParam = new Document("$limit",30);
AggregateIterable<Document> aggregateIterable = timeCollection.aggregate(Arrays.asList(match, project,group,limitParam)).batchSize(1000).allowDiskUse(true);
long curStartTs = Calendar.getInstance().getTimeInMillis();
MongoCursor<Document> cursor = aggregateIterable.iterator(); //this line still taking around 15 seconds
long curEndTs = Calendar.getInstance().getTimeInMillis();
System.out.println("Cursor time - " + (curEndTs - curStartTs));
-
は今、私はとして集計パイプラインで$限度を渡すことによって、レコードを制限しています。
私は、2つの場合に時間変動がない理由を理解できません。 パイプラインに制限を設けた後でも、パイプラインに制限がない場合、aggregateIterable.iterator()の場合と同じ時間がかかるのはなぜですか?
ありがとうございます。
種類について、
Vibhav
ありがとう@Clement。これは非常に役に立ちました。 –