I just found out that wildcard index on mongodb 4.2, doing a COLLSCAN
for $ne
query. So I was wondering, whether I did something wrong, or it was currently not being supported. And here I was looking a solution to use indexing for my ever growing (unstructured) extra
field while using $ne
operation. Because my extra
field will store many kind of key-value string data.
This is my query,
db.coll.explain(true).find({"extra.tag": {$ne: "dummy-tag"}})
And here’s is the explain()
result,
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 10133998.0,
"executionTimeMillis" : 5018.0,
"totalKeysExamined" : 0.0,
"totalDocsExamined" : 10184077.0,
"executionStages" : {
"stage" : "COLLSCAN",
"filter" : {
"extra.tag" : {
"$not" : {
"$eq" : "dummy-tag"
}
}
},
"nReturned" : 10133998.0,
"executionTimeMillisEstimate" : 394.0,
"works" : 10184079.0,
"advanced" : 10133998.0,
"needTime" : 50080.0,
"needYield" : 0.0,
"saveState" : 10184.0,
"restoreState" : 10184.0,
"isEOF" : 1.0,
"direction" : "forward",
"docsExamined" : 10184077.0
},
"allPlansExecution" : [
]
},
This is how I create my wildcard index
db.coll.createIndex({"extra.$**": 1})
Indexes on my collection
"indexSizes" : {
"_id_" : 102354944.0,
...
...
...
"extra.$**_1" : 110243840.0
},
Sample of document, due to the nature of our data, I omit some of the values
{
"_id" : ObjectId("5c582f5577612608f3e6a333"),
"email" : "",
"createdAt" : ISODate(),
"name" : "" ,
"firstname" : "",
"lastname" : "",
"birthDate" : ISODate(),
"gender" : "",
"phone" : "",
"city" : "",
"country" : "",
"company" : "",
"labels" : [
"dummy-label"
],
"index" : 0.0,
"state" : "ACTIVE",
"extra" : {
"tag" : "dummy-tag",
"note" : "dummy note"
}
}
Please let me know If I’m not clear enough with my question. Thank you