나는 Post라는 콜렉션을 가지고 있습니다. 나는 항상 각 문서는 이러한 필드를 갖게됩니다 매핑 시스템을 가지고 :mongoDB 인덱스 전략
- 아이디 (INT)
- 대상 (문자열)
- 유형 (문자열)
- 을 CLIENT_ID
- USER_ID 업데이트 됨 (문자열, 11 int 타임 스탬프)
- 생성됨 (문자열, 11 int 타임 스탬프)
- enabled (bool)
이 모음집은 API 스키마에서 출력되도록 액세스됩니다.
그래서 몇 가지 일반적인 요청 될 수 있습니다/post?type=image&user_id=2
/post?updated=35234423&order_by=client_id
/post?enabled=true&order_by=id
은 특정 필드를 찾거나 정렬 할 필드에 그것을 만들에는 100 % 보장은 없습니다. 테이블 데이터 8GB의에 도달 할 때
최근,이 오류가 시작하기 :
"localhost:27017: too much data for sort() with no index. add an index or specify a smaller limit"
나는 몽고의 인덱스에 대한 설명서를 살펴 보았다 및 어려운 그것과 같은 방식으로 작동하는지 이해하는 것이 발견 MySQL 인덱스.
인덱싱에서 발견 된 일부 스레드 : MongoDB - too much data for sort() with no index error은 특정 정렬 필드를 사용하여 인덱스가 맞춰 지도록 제안하는 것 같습니다. 분명히 필자의 필터링과 분류가 많은 선택 사항 일 때 나는 그것을 할 수 없다.
누군가 내 테이블의 모든 필드에 대해 색인을 생성해야하는지에 관해 확고한 해결책을 제시 할 수 있습니까? 피드백들에 대한
덕분에, 나는 자동 색인 기능을 구축하기 시작했습니다
는public function get() {
$indices['Post'] = array(
'fields' =>
array(
'id' => array('unique' => true, 'dropDups' => true, 'background' => true),
'client_id' => array('dropDups' => true, 'background' => true),
'image_id' => array('dropDups' => true, 'background' => true),
'user_id' => array('dropDups' => true, 'background' => true),
'publish_target' => array('dropDups' => true, 'background' => true),
'type' => array('dropDups' => true, 'background' => true),
'status' => array('dropDups' => true, 'background' => true),
'text' => array('background' => true)
)
);
foreach ($indices as $key => $index) {
/* set the collection */
$collection = $this->mongoDB->{$key};
/* delete the indexes */
$collection->deleteIndexes();
/* loop the fields and add the index */
foreach ($index['fields'] as $subKey => $data) {
$collection->ensureIndex($subKey, array_merge($data, array('name' => $subKey)));
}
}
/* return the list */
return $indices;
}
검색어를 공유 할 수 있습니까? 분석하는데 도움이 될까요? – user10
@ user10 그는 반쯤 내려다 보면 그의 quireies의 exmaples를 공유합니다. 여기가 https://jira.mongodb.org/browse/SERVER-3071이 정말 도움이 될 것입니다. – Sammaye