I have a collection of about 80 million documents, each of them storing an array of tags in the tags
field, e.g:
{text: "blah blah blah...", tags: ["car", "auto", "automobile"]}
The field tags
is indexed, so naturally the queries like this are almost instant:
db.documents.find({tags:"car"})
However the following queries are all very slow, taking several minutes to complete:
db.documents.find({tags:{$all:["car","phone"]}})
db.documents.find({tags:{$in:["car","auto"]}})
The problem persists even if the array only has a single item:
db.documents.find({tags:{$all:["car"]}}) //very slow too
I thought $all and $in should be able to work very fast because tags
is indexed but apparently it is not the case. Why?