Intro to Mongo Db ( part 1)

Understanding RDBMS 

Data is arranged in tables with rows and columns. Important concept of Normalization of database schema is followed. 1 NF requires each cell to have single value (or multivalues are stored as blobs of text which is not efficient when doing LIKE query). To avoid redundancy of data often more tables are created based on primary key. Though this is efficient way of storing, but often this creates a problem where Join of tables is required to yield query result. Now join is an expensive process of reading, though modern DB have reduced it by using cache mechanisms. even with such optimizations, joining tables is one of the most expensive operations that relational databases do. Additionally, if you end up needing to scale your database to multiple servers, you introduce the problem of generating a distributed join, a complex and generally slow operation.

Denormalizing for Performance
The dirty little secret (which isn’t really so secret) about relational databases is that once we have gone through the data modeling process to generate our nice nth normal form data model, it’s often necessary to denormalize the model to reduce the number of JOIN operations required for the queries we execute frequently.

MongoDB: Who Needs Normalization, Anyway?

In MongoDB, data is stored in documents. This means that where the first normal form in relational databases required that each row-column intersection contain exactly one value, MongoDB allows you to store an array of values if you so desire. MongoDB can natively encode such multivalued properties, we can get many of the performance benefits of a denormalized form without the attendant difficulties in updating redundant data.

MongoDB Document Format

Documents in MongoDB are modeled after the JSON (JavaScript Object Notation) format, but are actually stored in BSON (Binary JSON). Briefly, what this means is that a MongoDB document is a dictionary of key- value pairs, where the value may be one of a number of types:

  • Primitive JSON types (e.g., number, string, Boolean)
  • Primitive BSON types (e.g., datetime, ObjectId, UUID, regex)
  • Arrays of values
  • Objects composed of key-value pairs
  • Null

 

 

 

 

 

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s