MongoDB – Datatypes

MongoDB – Datatypes

MongoDB supports many datatypes. Some of them are -

  • Double- The double data type is used to store floating point values.
  • 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 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- Object data type stores embedded documents. If a document contains another document in the form of the key-value pair then such type of document is known as an embedded document.
  • 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.
  • Undefined- This MongoDB data type stores the undefined values.
  • JavaScript- These MongoDB data types store the JavaScript data without a scope. There is another data type to store data with a scope.
MongoDB – Create Collection (Prev Lesson)
(Next Lesson) MongoDB – Insert Document
', { 'anonymize_ip': true });