Skip to main content

What data types does BSON support?

BSON supports an extended set of types compared to JSON. The main ones are:

The basic types

  • Double, a floating-point number
  • String, a string (UTF-8)
  • Boolean, a logical type (true/false)
  • Int32, Int64, integers
  • Decimal128, an exact decimal number (e.g. for money)
  • Null, an empty value
  • Array, an array
  • Object, a nested document

The types unique to BSON

  • ObjectId, a unique document identifier (12 bytes)
  • Date, a date and time
  • Timestamp, a type used for replication and internal operations
  • Binary, binary data (e.g. files)
  • Regular Expression, regular expressions
  • JavaScript, JS code as a value
  • JavaScript (with scope), JS code plus context
  • Symbol, a deprecated type similar to a string
  • MinKey and MaxKey, internal values used for sorting
  • Undefined, a deprecated type, equivalent to undefined

Summary: BSON supports both ordinary data types (numbers, strings, arrays) and special ones, ObjectId, Date, Binary, Timestamp, and others, which help MongoDB work more efficiently than it would with plain JSON.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.