-1

I need to create a unique index on a field in mongoDB in order to prevent duplicates in my collection. I also want to create a single-field index on that same field in order to optimize for queries.

Do I need to create these two different indexes? Or will the unique index be used for queries as well?

Any help is appreciated!

gmat1014
  • 1,134
  • 10
  • 15
  • 1
    What makes you think you need a second index on the same column? It doesn't begin to make sense. – user207421 Mar 11 '15 at 23:49
  • It doesn't. Hence why I asked the question. I was unsure after reading this question http://stackoverflow.com/questions/12350879/advantage-of-a-unique-index-in-mongodb – gmat1014 Mar 12 '15 at 00:00

1 Answers1

1

The unique index will be used for queries, so the extra index is unnecessary.

You can test this, by looking at the indexes considered in the output from explain in the shell.

Martin
  • 5,119
  • 3
  • 18
  • 16