Index Prefix - doubt

I have a question about the Index Prefix.

I have the following index: ({a: 1}) (N1)

If I do my search like this: ({“a”: “bla”}), the index will be used.

If I create another index: ({a: 1, b: 1}) (N2)

And do the search: ({“a”: “bla”, “b”: “lala”}), the index used will still be N1.

Do you think it is necessary to create the composite index in this case?

What makes you think that? I think the index N2 will be used. To be convince you may run the following command after creating the indexes. {a: "bla", b: "lala"} ).explain().queryPlanner.winningPlan.inputStage.indexName ;

By the way, if you create indexes {a:1} and {a:1,b:1} their default respective names will be a_1 and a_1_b_1. It is easier to use those names rather than N1 and N2.

I used explain.
I noticed that doing a search that returns nothing he used the index a_1, now with two parameters and returning the result he used a_1_b_1.

What was the exact command you used? I am asking because if you do a find() with no parameter or parameters that are not a and not a and b, it should not use any index at all. For example, if you run { b: "yyy"} ).explain().queryPlanner.winningPlan.inputStage.indexName ;

you will get an error since the winningPlan does not use any index.