BSON Timestamp versus BSON Date

MongoDB has a BSON Timestamp type that is distinct from BSON Date. This distinction is important because application developers sometimes assume that both types serve the same purpose.

BSON Date

BSON Date is designed for application date-and-time values such as:

  • createdAt
  • updatedAt
  • publishedAt
  • expiresAt
  • scheduledAt

Example:

{ createdAt: ISODate("2026-10-22T10:30:00Z") }

BSON Timestamp

BSON Timestamp is a special internal type consisting of a seconds component and an ordinal component. MongoDB uses it in internal contexts, including replication-related metadata and the oplog.

It is not generally the preferred type for ordinary application timestamps.

In mongosh, a Timestamp can be constructed using the shell helper:

Timestamp(10, 1)

This illustrates the type's two components; it is not an application timestamp such as October 22, 2026.

Why the distinction matters

A field called createdAt normally represents a real-world instant. BSON Date expresses that meaning directly and supports date operators and date comparisons.

BSON Timestamp is designed for specialized database uses and should not be selected simply because the field name contains the word timestamp.

Avoid relying on internal timestamps as business data

Do not treat an internal replication timestamp as a universal creation time for application documents. If your application needs an auditable creation time, store an explicit BSON Date field and define how it is populated and updated.

Date and Timestamp comparison
BSON Date: Application time values
Appropriate for event times, creation dates, expiry dates, and other application-level instants.
BSON Timestamp: Specialized internal type
Used in MongoDB internal contexts such as replication metadata.
Application audit field: Explicit Date field
Use a defined field such as createdAt when the application requires an auditable creation time.
Key Takeaways
  • BSON Timestamp and BSON Date are different BSON types.
  • BSON Date is the usual choice for application-level time values.
  • BSON Timestamp has specialized database uses.
  • A field's name does not determine its BSON type.
  • Store explicit application timestamps when business logic depends on them.
Knowledge Check

Which type should normally be used for an application's `createdAt` field?