I have a collection of approximately 80 million documents, each of which stores an array of tags in the tags field, for example:
{text: "blah blah blah...", tags: ["car", "auto", "automobile"]}
The tags field is indexed, so naturally such queries are almost instantaneous:
db.documents.find({tags:"car"})
However, the following queries run very slowly in minutes:
db.documents.find({tags:{$all:["car","phone"]}}) db.documents.find({tags:{$in:["car","auto"]}})
The problem persists even if the array has only one element:
db.documents.find({tags:{$all:["car"]}})
I thought $ all and $ in should work very quickly because tags indexed, but apparently this is not the case. Why?
source share