Error while using hint(Index) in explain plan

Hi Team ,
I am getting below error , while running explain plan using a hint with index.
db.collection.explain().find({“createdDateUTC” : ISODate(“2021-04-14T00:48:30.820Z”)}).hint({“createdDateUTC”:1});
uncaught exception: Error: explain failed: {
“operationTime” : Timestamp(1678115286, 84),
“ok” : 0,
“errmsg” : “error processing query: ns=ATTPT.davidTree: createdDateUTC $gt new Date(1618361310820)\nSort: {}\nProj: {}\n planner returned error :: caused by :: hint provided does not correspond to an existing index”,
“code” : 2,
“codeName” : “BadValue”,
“$clusterTime” : {
“clusterTime” : Timestamp(1678115286, 84),
“signature” : {
“hash” : BinData(0,“cRm/DMwcuvEC13V1XLzhqpXdIZA=”),
“keyId” : NumberLong(“7154570222622474241”)
}
}
}

.

Hello @Prince_Das,

It seems the provided index in hint() is not present, can you please make sure is that index present or not by db.collection.getIndexes() command,

Second, you need to pass explain() at the end of the query, like this.

db.collection.find({...}).hint({...}).explain()
2 Likes