I am running the following query and it is take on average 9 seconds to return the results. There are no filters on it, so I am not sure an index would help. Why is this running so slowly? There are only 250 objects in there, and only 4 fields (all text).
Country.collection.find({},:fields => ['country_name', 'country_code']).to_json
"cursor":"BasicCursor",
"nscanned":247,
"nscannedObjects":247,
"n":247,
"millis":0,
"nYields":0,
"nChunkSkips":0,
"isMultiKey":false,
"indexOnly":false,
"indexBounds":{},
"allPlans":[{"cursor":"BasicCursor","indexBounds":{}}]
The cpu, memory and disk on the machine do not even notice the query run. Any help would be appreciated.
Create indexes on the 'country_name' fiels using :
db.countries.ensureIndex({country_name:1});
That will speed your query enormously You can learn more about indexes here
PS- you can type 'it' to display more when you see the 'has more' phrase, or you can display all the result without the 'has more' by using:
db.countries.find({}, {'country_name' : 1, 'country_code' : 1}).forEach(printjson)
and you can always set the profiler by using:
>use databaseName;
> db.setProfilingLevel(2); // 2 tell the profiler to catch everything happened inside the DB
You can learn more about profiler here
and you can display the data inside the profiler using
> db.system.profile.find()
This method will give you more info about your database and what's going on inside.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With