How to MongoDB- Data modeling & Data Types

MongoDB stores data in the form of BSON -Binary encoded JSON documents which support a rich collection of types. Fields in BSON documents may hold arrays of values or embedded documents.Data in MongoDB has a flexible schema.documents in the same collection. They do not need to have the same set of fields or structure, and common fields in a collection’s documents may hold different types of data.

MongoDB Data Modeling


considerations while designing Schema

Design your schema according to user requirements.

Combine objects into one document if you will use them together. Otherwise, separate them (but make sure there should not be need of joins).You should duplicate the data but in a limit because disc space is cheaper than compute time.

You should duplicate the data but in a limit, because disc space is cheaper than computer time.

Do joins while writing, not on reading.

Optimize your schema for most frequent use cases.

Do complex aggregation in the schema.


MongoDB Datatypes

MongoDB supports many data types. Some of them are listed below

Data TypesDescription
StringString is the most commonly used datatype. It is used to store data. A string must be UTF 8 valid in mongodb.
IntegerInteger is used to store the numeric value. It can be 32 bit or 64 bit depending on the server you are using.
BooleanThis datatype is used to store boolean values. It just shows YES/NO values.
DoubleDouble datatype stores floating point values.
Min/Max KeysThis datatype compare a value against the lowest and highest bson elements.
ArraysThis datatype is used to store a list or multiple values into a single key.
ObjectObject datatype is used for embedded documents.
NullIt is used to store null values.
SymbolIt is generally used for languages that use a specific type.
DateThis datatype stores the current date or time in unix time format. It makes you possible to specify your own date time by creating object of date and pass the value of date, month, year into it.

Anwar Yakkiparamban

Anwar Yakkiparamban is the founder of Lauyou Learning. Prior to Lauyou learning, Anwar worked at ARD Engineering & Development, Qatar. He holds bachelor degree in Electronics and Communication Engineering from Govt. Engineering College Idukki.

You may also like...