I have a collection called survey_data which has following fields
- topic_id
- indicator_id
- population_id
The survey_data has over 2.8M records. I want to fetch the populations from populations collection for a given set of indicator_id and topic_id. But the query below is taking 20 seconds even after adding a compound index for all the fields.
db.survey_data.find({"topic_id":60,"indicator_id":16)
How can i improve the performance? May be a single query using "mongoid" for rails3 would be preferred.
Explain { "cursor" : "BtreeCursor data_source_index", "isMultiKey" : false, "n" : 2261852, "nscannedObjects" : 2261852, "nscanned" : 2261852, "nscannedObjectsAllPlans" : 2261852, "nscannedAllPlans" : 2261852, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 21, "nChunkSkips" : 0, "millis" : 19952, "indexBounds" : { "data_source_id" : [ [ 60, 60 ] ] }
SurveyData Index: index({data_source_id: 1, data_source_year_id: 1, indicator_id: 1, indicator_option_id: 1, country_id: 1, provinces_state_id: 1, health_regions_id: 1, health_regions_type_id: 1, other_administrative_boundary_id: 1, sub_population_options_id: 1, reportability_id: 1}, {name:"survey_data_index", background: true })