MongoDB seems to use an inefficient query pattern when one index is a subset of another index.
class Model
field :status, :type => Integer
field :title, :type => String
field :subtitle, :type => String
field :rating, :type => Float
index([
[:status, Mongo::ASCENDING],
[:title, Mongo::ASCENDING],
[:subtitle, Mongo::ASCENDING],
[:rating, Mongo::DESCENDING]
])
index([
[:status, Mongo::ASCENDING],
[:title, Mongo::ASCENDING],
[:rating, Mongo::DESCENDING]
])
end
The first index is used when querying on status, titleand subtitleboth sorting by ratingand when querying only on statusand titleand sorting by rating, although using javascript explain()together with hint()the console states that using the second index is 4 times faster.
How can I tell Mongoid to tell MongoDB to use the second index?
source
share