MongoDB database Data Types

MongoDB is a No SQL database that uses document as its data structure to store user's data. MongoDB is a schema-less database in the sense that you do not require to define your fields in advance as well as different structured document can reside in the same collection. This is not possible in case of traditional RDBMS like MySQL, SQL Server, Oracle etc.

A document in MongoDB consists of key value pairs. Keys are written as strings but values can belong to one of the several data types allowed in MongoDB.

Please always refer to the documentation or online resources for your specific version of MongoDB as an application features are always tend to change.

DataType Description
String This commonly used datatype contains a string of text (or any other kind of characters). This datatype is used mostly for storing text values (for example, "Country" : "India"}.
Integer (32b and 64b) This type is used to store a numerical value (for example, { "Rank" : 1 } ). Note that there are no quotes placed before or after the integer.
Boolean This datatype can be set to either TRUE or FALSE.
Double This datatype is used to store floating-point values.
Min/Max keys This datatype is used to compare a value against the lowest and highest BSON elements, respectively.
Arrays This datatype is used to store arrays (for example, ["Membrey, Peter","Plugge,Eelco","Hows, David"]).
Timestamp This datatype is used to store a timestamp. This can be handy for recording when a document has been modified or added.
Object This datatype is used for embedded documents.
null This datatype is used for 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 (POSIX time).
Object ID * This datatype is used to store the document’s ID.
Binary Data * This datatype is used to store binary data.
Regular Expression * This datatype is used for regular expressions. All options are represented by specific characters provided in alphabetical order.
JavaScript Code * This datatype is used for JavaScript code.

The asterisks mean that the last five data types (Date, Object ID, Binary Data, Regular Expression and JavaScript Code) are non-JSON types; specifically, they are special data types that BSON allows you to use. You can identify your data types by using the $type operator.

You can embed or reference one document inside another.

Comments

Back To Top

Popular posts from this blog

How to save video from Internet Explorer

error 18 at 0 depth lookup: self signed certificate

How to check fragmentation in MySQL tables