The following command generates a plan that does not utilize the a_1_b_1_c_1 index.
> db.testcounthint.explain().count({a:1, b:2}, {hint: "a_1_b_1_c_1"}) { "queryPlanner" : { "plannerVersion" : 1, "namespace" : "test.testcounthint", "indexFilterSet" : false, "parsedQuery" : { "$and" : [ { "a" : { "$eq" : 1 } }, { "b" : { "$eq" : 2 } } ] }, "winningPlan" : { "stage" : "COUNT", "inputStage" : { "stage" : "COUNT_SCAN", "keyPattern" : { "b" : 1, "a" : 1 }, "indexName" : "b_1_a_1", "isMultiKey" : false, "isUnique" : false, "isSparse" : false, "isPartial" : false, "indexVersion" : 1 } }, "rejectedPlans" : [ ] }, "serverInfo" : { "host" : "grey.local", "port" : 27017, "version" : "3.2.5", "gitVersion" : "34e65e5383f7ea1726332cb175b73077ec4a1b02" }, "ok" : 1 }
Please note that without the explain, the correct plan is generated.
db.testcounthint.count({a:1, b:2}, {hint: "a_1_b_1_c_1"})
Additionally, note that the following command with explain generates the correct plan:
> db.testcounthint.explain().find({a:1,b:2}).hint("a_1_b_1_c_1").count() { "queryPlanner" : { "plannerVersion" : 1, "namespace" : "test.testcounthint", "indexFilterSet" : false, "parsedQuery" : { "$and" : [ { "a" : { "$eq" : 1 } }, { "b" : { "$eq" : 2 } } ] }, "winningPlan" : { "stage" : "COUNT", "inputStage" : { "stage" : "COUNT_SCAN", "keyPattern" : { "a" : 1, "b" : 1, "c" : 1 }, "indexName" : "a_1_b_1_c_1", "isMultiKey" : false, "isUnique" : false, "isSparse" : false, "isPartial" : false, "indexVersion" : 1 } }, "rejectedPlans" : [ ] }, "serverInfo" : { "host" : "grey.local", "port" : 27017, "version" : "3.2.5", "gitVersion" : "34e65e5383f7ea1726332cb175b73077ec4a1b02" }, "ok" : 1 }