Single Field Indexes with dot notation

Hi,
If I have an index like the one in the lesson {“subdoc.IndexField”}, if I try to query only the subdoc will it use the index?
Thanks!

It would only use whatever field you’ve indexed. In your case, only when you use IndexField.

2 Likes

Hi @LuisVibranovski,

Following on @007_jb’s reply. You can read more details here:

https://docs.mongodb.com/manual/core/index-single/#create-an-index-on-an-embedded-field

If you are want index to be used to subdoc field as a whole, you can create an index on {subdoc: 1}. If not, then it will only use index when queried on the indexed field {“subdoc.IndexField”}.

Kanika

Thanks for your answer!

1 Like