Skip to main content

What is an ObjectId?

Entry MongoDB
Quick Answer ObjectId is MongoDB's default primary key type - a 12-byte unique identifier automatically generated for the _id field. It encodes: 4-byte timestamp, 5-byte random value (unique per machine/process), 3-byte incrementing counter. This makes ObjectIds roughly sortable by creation time, unique across distributed systems, and generated client-side without DB round-trips.

Answer

ObjectId is the default unique identifier for documents. It includes timestamp and machine-specific information to ensure global uniqueness.
S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice