I have to save a lot of documents which I am going to show on a website and I have a Mongo database to save them.
I know that mongo can automatically generate a random ID for each item in a collection and I also know that you can create a hashed index to increase the quick search.
I will be using the hash of the sha1 document (or maybe another one) as the web identifier for each document, and I was wondering if it might be a good idea to use it as a custom index on Mongo.
It doesn't matter that someone does sh1 in a random document to search for it on the web, I mean, security is not a problem because the documents will be public.
I have seen that other people have used a custom index and say it is useful
In my opinion, this would have the following advantages:
- It's a faster way to find documents, because you can search by dominate hash and not by entire document.
- The ID is already an index so you will save an index.
- You can save storage space because you don't need to save the hash separately.
- The size sha1 is smaller than the default mongo ID, so you may have more indexes in memory at the same time.
And as disadvantages:
- You must manage the collisions manually. (I can use a "larger" hash function)
- You have to generate the hash by yourself.
- it will be more difficult to shorten the documents and you may have additional keys.
But are there any drawbacks?
Thank you !