What is BSON in MongoDB?

April 30, 2024 / 3 mins read
object id in mongodb

For the database data model of Mongodb JSON is perfect solution.But there are some issues with JSON like:

  1. JSON have limited data types and also lacks of support for dates and binary data.
  2. JSON objects and properties don't have fixed length, so it makes traversal slower.

To solve this problem BSON came into picture. BSON is simply binary representation of JSON.

BSON support wide range of data types. For example in JSON we have number data type for all int, long, decimal and double numbers but in BSON we have separate data type for each one of them like int32, int64, decimal128 and double.

JSON lack some major data types support like date and binary data. If database support more data types then it will be powerful. But for JSON we had some limitation on data types, but BSON solved that problem.

Now there is one question like Which format MongoDB use JSON or BSON? and answer is MongoDB uses BSON for storing internally and also over the network. But BSON is superset of JSON. So it also support JSON. If we are using any programming language with MongoDB. Then we can work with data types of that language and driver will take of converting them into BSON and querying back them from documents.

Learn more about How to use type of field in document to query ? see : $type operator in MongoDB

MongoDB

$type operator

MongoDB Data types

Discover more