test@local(2.8.0-rc4) > db.foo.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "test.foo"
},
{
"v" : 1,
"key" : {
"a" : 1
},
"name" : "a_1",
"ns" : "test.foo"
}
]
test@local(2.8.0-rc4) > db.foo.find({a:1})
{ "_id" : ObjectId("54b588d2d7a7afb83a377935"), "a" : 1 }
test@local(2.8.0-rc4) > db.foo.find({a:1}).hint("a_1")
{ "_id" : ObjectId("54b588d2d7a7afb83a377935"), "a" : 1 }
test@local(2.8.0-rc4) > db.foo.find({a:1}).hint("a_1").explain()
2015-01-13T16:07:09.059-0500 I QUERY Error: explain failed: {
"ok" : 0,
"errmsg" : "error processing query: ns=test.foo limit=0 skip=0\nTree: a == 1.0\nSort: {}\nProj: {}\n planner returned error: bad hint",
"code" : 2
}
at Error (<anonymous>)
at Function.throwOrReturn (src/mongo/shell/explainable.js:34:19)
at constructor.finish (src/mongo/shell/explain_query.js:188:36)
at DBQuery.explain (src/mongo/shell/query.js:434:25)
at (shell):1:32 at src/mongo/shell/explainable.js:34
test@local(2.8.0-rc4) > db.foo.find({a:1}).hint("a_1").explain(true)
2015-01-13T16:07:10.756-0500 I QUERY Error: explain failed: {
"ok" : 0,
"errmsg" : "error processing query: ns=test.foo limit=0 skip=0\nTree: a == 1.0\nSort: {}\nProj: {}\n planner returned error: bad hint",
"code" : 2
}
at Error (<anonymous>)
at Function.throwOrReturn (src/mongo/shell/explainable.js:34:19)
at constructor.finish (src/mongo/shell/explain_query.js:188:36)
at DBQuery.explain (src/mongo/shell/query.js:434:25)
at (shell):1:32 at src/mongo/shell/explainable.js:34
So hint by name works, but with explain() appended it breaks.