Skip to main content

Data Types

  • String− This is the most commonly used datatype to store the data. String in MongoDB must be UTF-8 valid.
  • Integer− This type is used to store a numerical value. Integer can be 32 bit or 64 bit depending upon your server.
  • Boolean− This type is used to store a boolean (true/ false) value.
  • Double− This type is used to store floating point values.
  • Min/ Max keys− This type is used to compare a value against the lowest and highest BSON (Binary JSON) elements.
  • Arrays− This type is used to store arrays or list or multiple values into one key.
  • Timestamp− ctimestamp. This can be handy for recording when a document has been modified or added.
  • Object− This datatype is used for embedded documents.
  • Null− This type is used to store a Null value.
  • Symbol− This datatype is used identically to a string; however, it's generally reserved for languages that use a specific symbol type.
  • Date− This datatype is used to store the current date or time in UNIX time format. You can specify your own date time by creating object of Date and passing day, month, year into it.
  • Object ID− This datatype is used to store the document's ID.
  • Binary data− This datatype is used to store binary data.
  • Code− This datatype is used to store JavaScript code into the document.
  • Regular expression− This datatype is used to store regular expression.

BSON (Binary JSON)

BSON /ˈbiːsən/ is a computer data interchange format. The name "BSON" is based on the term JSON and stands for "Binary JSON". It is a binary form for representing simple or complex data structures including associative arrays(also known as name-value pairs), integer indexed arrays, and a suite of fundamental scalar types. BSON originated in 2009 at MongoDB. Several scalar data types are of specific interest to MongoDB and the format is used both as a data storage and network transfer format for the MongoDB database, but it can be used independently outside of MongoDB. Implementations are available in a variety of languages such as C, C++, C#, D, Delphi, Erlang, Go, Haskell, Java, JavaScript, Lua, OCaml, Perl, PHP, Python, Ruby, Rust, Scala, Smalltalk, and Swift.

JSON vs BSON

JSON (JavaScript Object Notation)-like XML, for example - is a human-readable standard used for data exchange. JSON has become the most widely used standard for data exchange on the web. JSON supports data types like booleans, numbers, strings, and arrays.

BSON, however, is the binary encoding that MongoDB uses to store its documents. It is similar to JSON, but it extends JSON to support more data types, likeDate. BSON documents, unlike JSON documents, are ordered. BSON usually takes less space than JSON and is faster to traverse. BSON, since it is binary, is also quicker to encode and decode.

Capped Collections

Capped collections are fixed-size collections that support high-throughput operations that insert and retrieve documents based on insertion order. Capped collections work in a way similar to circular buffers: once a collection fills its allocated space, it makes room for new documents by overwriting the oldest documents in the collection.

Capped Collections - MongoDB Manual