Why does ObjectId simplify configuration in MongoDB?

I continue to read that using ObjectId, since a unique key simplifies the outline, but I have not seen a detailed explanation of why this is so. Can someone shed some light on this?

The reason I ask is because I want to use the English string (which will be unique, obviously) as a unique key, but I want to make sure that it does not connect me later.

+3
source share
5 answers

I only recently got acquainted with mongoDB, so take this with salt, but I suspect that the fragments are probably more efficient when using ObjectId, and your own key values ​​because the ObjectId part will indicate which machine or fragment, what The document has been created. The bottom of this page in mongo docs explains what each part of the ObjectId means.

+4
source

I asked this question in the Mongo user list, and basically the answer was that it normally generates your own _id value, and it will not obstruct the outline. For me, sometimes it is necessary to have numeric values ​​on _id, for example, when I use them in the URL, so I create my own _id in some collections.

+2

ObjectId . , , . :)

0

. , .

0

, ObjectID, , .

(http://docs.mongodb.org/manual/core/sharded-cluster-internals/ " " ):

"[T] [ObjectID] , , . [] , , . ."

, OID "", , , , OID, , - / . ( OID, - , ..).

In contrast, if you select a random row as the fragment key, the records will be evenly distributed across the cluster, and your throughput will be the total input-output of the entire cluster.

(EDIT should be complete: with the key of the OID fragment, since the new records landed on the “rightmost” fragment, the balancer will handle moving them elsewhere, so they will end up on other machines. But this does not solve the I / O problem it really makes her worse.)

0
source

Source: https://habr.com/ru/post/1778557/


All Articles