DataTypes of MongoDB


MongoDB store the documents in the format of BSON. BSON is a serialization format used to store documents and make remote procedure calls in MongoDB."BSON" is a combination of the words “binary” and “JSON”.

We Can Think of BSON as a binary representation of JSON (JavaScript Object Notation) documents.
So all the BSON Types(datatypes) are supported in MongoDB, every BSON datatype has a number code so we can represent the datatype either with it's number or alias type.

Let's view some of the key datatype alias and its numeric code of BSON.

Type Number   Type Number
Double 1   Null 10
String 2   Regular Expression 11
Object 3   DBPointer 12
Array 4   JavaScript 13
Binary data 5   Symbol 14
Undefined 6   int 16
ObjectId 7   timestamp 17
Boolean 8   long 18

Note:-

  1. we can specify the datatype of a field when we are creating schema with createCollection(), the above data types specify these type of data we can pass to fields while doing insertion or updation operations.
  2. Each and every type is assigned with a numeric code so we can specify the type using either name of type or its numeric value.
    means "int" equalent numeric is "16" so these two declarations are valid "age:int" or "age:16" at the schema declaration
Copyright © 2018-2020 TutorialToUs. All rights reserved.