I have a compound index set up on a mongo collection, and no matter how specifically I target the prefix, I can't get the query to use it.
How index was created:
db.collection.createIndex({"insert_time":-1,"name":"text"},{background: true})
Index specification output:
db.collection.getIndexes()
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "db.collection"
},
{
"v" : 2,
"key" : {
"insert_time" : -1,
"_fts" : "text",
"_ftsx" : 1
},
"name" : "insert_time_-1_name_text",
"ns" : "db.collection",
"background" : true,
"weights" : {
"name" : 1
},
"default_language" : "english",
"language_override" : "language",
"textIndexVersion" : 3
}
]
But when I run even the simplest query on insert_time, explain() shows me that the winning plan is to do COLLSCAN, and not use any index:
db.collection.find({"insert_time": ISODate("2018-08-
05T19:00:00Z")}).explain()
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "db.collection",
"indexFilterSet" : false,
"parsedQuery" : {
"insert_time" : {
"$eq" : ISODate("2018-08-05T19:00:00Z")
}
},
"winningPlan" : {
"stage" : "COLLSCAN",
"filter" : {
"insert_time" : {
"$eq" : ISODate("2018-08-05T19:00:00Z")
}
},
"direction" : "forward"
},
"rejectedPlans" : [ ]
},
"serverInfo" : {
"host" : "foo",
"port" : 0000,
"version" : "3.4.10",
"gitVersion" : "078f28920cb24de0dd479b5ea6c66c644f6326e9"
},
"ok" : 1
}
Even though the index is specified as a "compound index", my understanding is that I should be able to search by a "prefix", which in this case, insert_time is. Any ideas as to why mongo won't use my index?