Create index on a field with distinct value is good or not?

In Chapter 2, Lecture 1, the example creates an index on SSN field. I think that we will need the index in that field anyway to avoid collection scan. May I ask if it’s a good option as usually SSN is unique per person? So we may end up with a very big index with different values. Is it good practice? I’m asking for my curiosity here only as I belive that we don’t have the option to not create the index on SSN field if we need to search on that field anyway.

Hi @Hoang_HUA

Creating indexes with high cardinality fields (like an SSN) is good practice. It can be combined with other good practices like making that field part of a compound index and following the Equality Sort Range (ESR) recommendation for which fields to use in the compound index.

This and several other recommendations / good practices are discussed in this blog post..

Hope this helps answer your question and good luck with the rest of the course!
Eoin