Difference between revisions of "MongoDB ObjectIds"
From mi-linux
Jump to navigationJump to searchLine 20: | Line 20: | ||
{| border="1" cellpadding=2 cellspacing=2 | {| border="1" cellpadding=2 cellspacing=2 | ||
− | |0||1||2||3||4||5|||6||7||8||9||10||11 | + | |0||1||2||3||4||5|||6||7||8||9||10 || 11 |
|- | |- | ||
− | |time||machine|| pid||inc | + | |colspan="4"| time||machine|| pid||inc |
|} | |} | ||
Revision as of 13:55, 21 October 2016
Main Page >> MongoDB >>MongoDB Workbook >> Object IDs
Object IDs
You may have noticed that the database creates an unique object for each document:
db.deptCollection.find().pretty()
Examine the output carefully and you will notice for each department in the collection something like:
"_id" : ObjectId("5808e3d2ec0ff55100af2649")
An ObjectId is like a primary key found in relational databases, except in this case it is globally unique across the whole database, not just one table. It is similar to objectIds found in object-oriented programming languages.
ObjectIds created by MongoDB consist of 12 bytes:
ObjectID layout
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
time | machine | pid | inc |
Where:
- time: system time
- machine: machine id
- pid: process id
- inc: incremental number