Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB Indexes: String vs Int

New to Database management. I have a books database and I want to create an index for the ISBN which is 13 characters in length. Example: '9781509825889'

Currently I'm using a string index but I've read conflicting points on whether to store as an int or a string for indexing optimization.

It looks like I have Int32 or Int64 options and I think the above ISBN is too big for Int32 but is it worth switching to an Int64 for query optimization or should I just stick with string? Is there any significant performance gain?

Thanks

like image 648
Jat90 Avatar asked Sep 03 '26 01:09

Jat90


1 Answers

MongoDb indexes does not depends on the data type of the fields, so it does not matters you put it into String or Int32 or Int64.

All indexes are hashed that's why it does not depends on the data type you used.

References:

  1. Does field type matter in a MongoDB index?
like image 52
krishna Prasad Avatar answered Sep 04 '26 15:09

krishna Prasad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!