Trantor Liu
Trantor Liu

Reputation: 9126

MongoDB - Should I index tags with tag names or ObjectId?

As title, I am considering which key is better: tag names or ObjectId. Since tag names are unique, it OK to use them as index. What should I concern on choosing keys?

Upvotes: 0

Views: 240

Answers (1)

Devesh
Devesh

Reputation: 4550

Using the tag name in your case is good , as you do not have to create extra index for _id as mongodb automatically create the index for _id field. The only concern you should have that it remains all the time unique :) . If you create tag as another key and then index it , you will waste the space for the _id index key. So better use the tag as _id

Upvotes: 1

Related Questions