Hey there, I saw several topics about this point on the net but I never found exactly if I should prefer random or custom _id.
Is there anyone that can explain it to me? Furthermore, Is there any difference between a creation document and an update document using random or custom _id?
Indexing documents with an auto generated id is more efficient than using a custom id so is ideal for immutable data. If you want to update data you may benefit from a custom id as updating gets easier and you do not need to search for the id first.
Regarding update procedure. Using a custom _id is probably better I know from the beginning the document that I want to update, while with a random _id I should search it with a query? Am I right?
If you are going to update a lot it makes sense to sacrifice a bit of indexing speed in order to simplify updates.
In your opinion, executing a query (first operation) to get the random _id to be updated (second operation) is more expensive (cpu/jvm) than updating directly the document with the custom _id?
Yes. It therefore comes down to the ratio of inserts to updates and which is best to optimise for.
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.