Do you need a leading column to be Indexed on Mongo DB ?

26 views
Skip to first unread message

Bhaskar Sarma

unread,
Jun 25, 2017, 4:09:47 AM6/25/17
to mongodb-user
Hi Experts, I created a small collection chap2, with the following details, I created Index on col1 Column, when I try to query col1 I see the plan uses IXSCAN, Now when I try to use Col2,Col1 or Col1,Col2 I see the plan to be same. So does it really matter the order of columns in Index for Mongo ? or is it by case to case basis ?

Bhaskar.

Weishan Ang

unread,
Jun 27, 2017, 11:01:31 AM6/27/17
to mongodb-user
It does matter, if you look at the KeysExamined Vs KeysRetrieved, you will notice a difference in the ratio. The best ratio is, of course, 1:1.

Wan Bachtiar

unread,
Jun 28, 2017, 11:00:18 PM6/28/17
to mongodb-user

Hi Bhaskar,

You may find Blog: Optimising MongoDB compound indexes to be a great resource.

See MongoDB Indexes for more information. If you still have questions about indexing, please provide:

Regards,

Wan.

Reply all
Reply to author
Forward
0 new messages