Introduction to Mongo db Storing Data

Rama Sagar
Posted by in NoSql category on for Beginner level | Points: 250 | Views : 5829 red flag

MongoDB can be used as a file system, taking advantage of load balancing and data replication features over multiple machines for storing files.
Recommendation
Read Introduction to MongoDB Mongo Shell before this article.

Introduction

In this article we will learn about storing data in Mongo. Mongo is a document database and a document can be structured pretty much anyway we want. Mongo imposes no schema restrictions and does not demand that we declare a schema.

Previous articles have provided an introduction to mongo dB and the set up and installation, and few command line options.You can get them from the following:


Objective

The objective of the article is to learn about Storing data in Mongo Database

We gonna take a look at storage engine, saving documents and updating documents.

The storage engine overview will help us understand the internals of how mongo lays out the information.

Saving documents and Updating documents will focus on the commands in order to save our documents.


Storage Internals

First let us talk about how data is stored by the engine…Now if our application wants to interact with some information that information is a memory in our application…It can talk to the server and the server has preeminence storage named in the disk….

The Question is how does the engine store the data??

 

 

Mongo uses Memory mapped Files the server cannot store all its information in memory.But it would like to think of information has just existing in being available to it at any given moment..so what it does is it creates a Mongo server and maps it using memory mapped files whenever it calls it into play a portion of that array the operating system takes care of loading it or saving it to the disk..When we wanna store a bit of information we handle it over the server,and the server scribbles it over a memory and that memory gets manged and serialized to disk.. The same process in reverse happens  when we want to read  data the server will attempt to access a portion of the large byte array which will be loaded as needed from the operating system..

so now byte arrays can be stored on disk...now the question arises here..how does our document which doesn't have schema that get saved and what format does it get saved??

The answer is BSON...The BSON specifications can be found on http://bsonspec.org/

The BSON data format has several advantages some key advantages are that there is very little marshaling necessary from BSON elementary datatypes into c datatypes that makes reading and writing very fast in any of the programming languages.we can learn more at http://bsonspec.org/.



Saving Data


Rules for saving data

Rule 1: A document must have an ID field.._id Every document in mongo must have an Id if we save one without an Id mongo will assign an id field,But every document we save must have an ID..

Rule 2: The size of the document in Mongo is currently limited to 16 Mega Bytes..if we need to store more than that 
we will have to store across multiple documents.This is something that may evolve in future releases.But this is the current limitation...

Conclusion


In this article we have learn about storage internals in mongo db and about BSON..In coming articles we will see the practical example.

Reference

http://bsonspec.org/
http://www.mongodb.org/ 

Page copy protected against web site content infringement by Copyscape

About the Author

Rama Sagar
Full Name: RamaSagar Pulidindi
Member Level: Silver
Member Status: Member,MVP
Member Since: 12/30/2012 1:51:40 AM
Country: India
ramasagar
http://www.ramasagar.com
A Software Profesional working in Microsoft .NET technologies since year 2008, and I work for Dake ACE. I am passionate about .NET technology and love to contribute to the .NET community at Dot Net Funda

Login to vote for this post.

Comments or Responses

Login to post response

Comment using Facebook(Author doesn't get notification)