Why do multiKey indexes block IndexOnly queries in MongoDB?

I am trying to use only the index when reading data from the collection in MongoDB, because I have several large documents, whereas for this query I need only one field.

Turns out I can't have indexOnly = true if the index is an multiKey index.

Here is the test I did:

db.test.drop()
db.test.insert({a:1})
db.test.ensureIndex({a:1})
db.test.find({a:1}, {_id:0, a:1}).explain()

-> indexOnly = true, isMultiKey = false

db.test.insert({a : [2,3]})
db.test.find({a:1}, {_id:0, a:1}).explain()

-> indexOnly = false, isMultiKey = true

The documentation mentions some of the limitations of multicid indexes, but not this one. Does anyone know how to use both multikey and indexonly?

+4
source share
2 answers

, indexOnly . , , , .

multiKey , { "a" : 1 }

{ "a" : [ 1 ] }

, , , "a" 1, multiKey. , , "a" .

+2

All Articles