이 쿼리는 응용 프로그램에 많은 시간이 걸립니다. 데이터베이스에는 약 2 백만 개의 레코드가 들어 있습니다.Doctrine에서 MongoDB 쿼리 최적화
$results = $queryBuilder
->field('extra.targetPlayerId')->exists(FALSE)
->field('permission')->equals('public')
->field('time')->gt($weekEndTime) // variable is timestamp
->field('time')->lte($startTime) // variable is timestamp
->map(
'function() {
var total = 0;
if (this.comments) {
total += this.comments.length;
}
if (this.likes) {
total += this.likes.length;
}
if (total > 0) {
emit(this.playerId, total);
}
}'
)
->reduce(
'function(key, values) {
var total = 0;
for (value in values) {
total += values[value];
};
return total;
}'
)->getQuery()->execute();
어떻게하면이 쿼리를 최적화 할 수 있습니까? 색인에 대한 제안을 해 줄 수 있습니까?