I'm having troubles understanding basic concepts of compound indexes. Let's say I have a collection with this schema:
{
_id: 1,
field1: 'aaa',
field2: 'bbb',
field3: 'ccc'
}
In https://docs.mongodb.org/manual/core/index-compound/ it says very clearly, and I understand, that this index: { field1: 1, field: 2}
will support queries only on field1
and on both field1 AND field2
, this make sense.
Now, What if I want to support queries on all fields (1, 2 and 3) where field 1 is always used?
I want to support the option to query on field1 AND field2
and field1 AND field3
on all field1 AND field2 AND field3
.
I know it's possible to create compound index for each of these query options, but the question is if I can use less compounds that will query in the same performance.
For example, if I have an index: {field1: 1, field2: 1, field3: 1}
and I query for field1 AND field3
, it will use this index, but the index bounds on field2
will be the "[MinKey, MaxKey]"
.
Does it worth it to create another index: {field1: 1, field3: 1}
?
{field1: 1, field3: 1}
, compare those two results, it will give you some clue... – zangw[MinKey, MaxKey]
index bounds. But it doesn't give me performance evaluation – TomG