Are they somewhat random?
I mean....would people be able to break them apart?
MongoDB uses ObjectIds as the default value of _id field of each document, which is generated while the creation of any document. The complex combination of ObjectId makes all the _id fields unique.
By default, MongoDB generates a unique ObjectID identifier that is assigned to the _id field in a new document before writing that document to the database. In many cases the default unique identifiers assigned by MongoDB will meet application requirements.
_id is the primary key on documents in a collection; with it, documents (records) can be differentiated from each one another. _id is automatically indexed. Lookups specifying { _id: <someval> } refer to the _id index as their guide. By default the _id field is of type ObjectID, one of MongoDB's BSON types.
An ObjectId in MongoDB is a 12-byte BSON type. In the 12-byte structure, the first 4 bytes of the ObjectId represent the time in seconds since the UNIX epoch. The next 3 bytes of the ObjectId represent the machine identifier. The next 2 bytes of the ObjectId represent the process ID.
They are not random and can be easily predicted :
A BSON ObjectID is a 12-byte value consisting of a 4-byte timestamp (seconds since epoch), a 3-byte machine id, a 2-byte process id, and a 3-byte counter
http://www.mongodb.org/display/DOCS/Object+IDs
Heres a javascript implementation of the MongoDB ObjectID (http://jsfiddle.net/icodeforlove/rN3zb/)
function ObjectIdDetails (id) { return { seconds: parseInt(id.slice(0, 8), 16), machineIdentifier: parseInt(id.slice(8, 14), 16), processId: parseInt(id.slice(14, 18), 16), counter: parseInt(id.slice(18, 24), 16) }; }
So if you have enough of them they leak quite a bit of information about your infrastructure. And you also know the object creation dates for everything.
IE: how many servers do you have, and how many processes each server is running.
They are usually generated on the client side by the driver itself. For example, in ruby, BSON::ObjectID can be used:
You can also generate your own ObjectIds. This is particularly useful if you want to use business identifiers.
MongoDB database drivers by default generate an ObjectID identifier that is assigned to the _id field of each document. In many cases the ObjectID may be used as a unique identifier in an application.
ObjectID is a 96-bit number which is composed as follows:
a 4-byte value representing the seconds since the Unix epoch (which will not run out of seconds until the year 2106)
a 3-byte machine identifier (usually derived from the MAC address),
a 2-byte process id, and
a 3-byte counter, starting with a random value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With