'MongoDB Index on columns (A,B) smaller than index on just A

I'm seeing a strange effect in MongoDB, and I was hoping someone can help me explain it.

As the title says, for the same collection, index

db.my_collection.createIndex({"arrayField.subfield1": 1, "arrayField.subfield2": 1});

is smaller than index

db.my_collection.createIndex({"arrayField.subfield1": 1});

Which I find very strange.

Sidenote: I know it is redundant to have 2 indexes with same prefix. These are just tryouts, and I happened to see the sizes of the 2 indexes.

Do you know what might be possible causes for this? I expected the opposite to happen.

It is not a matter of indexes still building in the background, as I've waited long enough, and the collection is only ~5million records.

I am using MongoDB 4.2.6 Community



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source