Skip to content
Justice Tech School

ObjectId and _id

Every document has a unique _id. If you do not give one, MongoDB creates an ObjectId, a 12 byte value that includes a timestamp. _id is always indexed.

Example
db.users.insertOne({ name: "Ada" })
// { acknowledged: true, insertedId: ObjectId("65a...") }
ObjectId("65a1b2c3d4e5f6a7b8c9d0e1").getTimestamp()

Exercise

Unique key field.

The field 

Quiz Test

What is _id?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.