Monday, 10 June 2013

Brief Overivew of MongoDB (NoSQL)

MongoDB is very powerful document oriented database; Discuss some of the basic concepts.

• A document is the basic unit of data for MongoDB, roughly equivalent to a row in
 a relational database management system like oracle or mysql.

• Similarly, a collection can be thought of as the schema-free equal to a table.

• A single instance of MongoDB can host multiple independent databases, each of
 which can have its own collections and permissions.

• MongoDB comes with a simple but powerful JavaScript shell, which is useful for
 the administration of MongoDB instances and data manipulation.

• Every document has a special key, "_id", that is unique across the document’s

A collection is a group of documents. If a document is the MongoDB same as of a row
in a relational database, then a collection can be like a table in oracle or mysql.

MongoDB is the concept of a document: an ordered set of keys with associated values.

A document differs by programming language, means row in a table(rdbms)
but most languages have a data structure that is a natural fit, such as a map, hash, or

In JavaScript, for example, documents are represented as objects:
{"Welcome" : "Good morning!!"}

This simple document contains a single key, "welcome", with a value of " Good morning!!".

Most documents will be more complex than this simple one and often will
contain multiple key/value pairs:

{" Welcome " : " Good morning!!", "Header" : 1}

Collections are schema-free. This means that the documents within a single collection
can have any number of different “shapes.”
For example, both of the following documents could be stored in a single collection:
{" Welcome " : “Good morning!!"}
{" Header" : 1}

A collection is identified by its name. Collection names can be any UTF-8 string, with a few restrictions:

The empty string (" ") is not a valid collection name.
• Collection names may not contain the character \0 (the null character) because this   
 delineates the end of a collection name.

Note:- Not recommendable create any collections that start with system., a prefix reserved for system collections. For example, the system.users collection contains the database’s users and the system.namespaces collection contains information about all of the database’s collections.

• User-created collections should not contain the reserved character $ in the name.
 The various drivers available for the database do support using $ in collection
 names because some system-generated collections contain it. You should not use
 $ in a name unless you are accessing one of these collections.


One convention for organizing collections is to use namespaced subcollections separated by the character.

For example, an application containing a blog might have a
collection named blog.posts and a separate collection named blog.authors.
This is for organizational purposes only—there is no relationship between the blog.

• GridFS, a protocol for storing large files, uses subcollections to store file metadata
separately from content chunks.
• The MongoDB web console organizes the data in its DBTOP section by
• Most drivers provide some syntactic sugar for accessing a subcollection of a given
collection. For example, in the database shell, will give you the blog collection,
and will give you the blog.posts collection.

Subcollections are very good way to organize data in MongoDB, and their use is highly

This is good for Social network, blogs and game related applications.


Set of documents is grouped by collection and groups collections into
databases.A single instance of MongoDB can host several databases, each of which can be thought of as completely independent.

A database has its own permissions, and each database is stored in separate files on disk. A good rule of thumb is to store all data for a single application in the same database.
Separate databases are useful when storing data for several application or users on the same MongoDB server.
Like collections, databases are identified by name. Database names can be any UTF-8

with the following restrictions:
• The empty string (" ") is not a valid database name.
• A database name cannot contain any of these characters: ' ' (a single space), ., $, /,
  \, or \0 (the null character).
• Database names should be all lowercase recommended.
• Database names are limited to a maximum of 64 bytes.

There are also several reserved database names, which you can access directly but have special rules.

These are as follows:
This is the “root” database, in terms of authentication. If a user is added to the
admin database, the user automatically inherits permissions for all databases.
There are also certain server-wide commands that can be run only from the admin
database, such as listing all of the databases or shutting down the server.

This database will never be replicated and can be used to store any collections that
should be local to a single server.

When Mongo is being used in a sharded setup , the config database
is used internally to store information about the shards.

By prepending a collection’s name with its containing database, you can get a fully
qualified collection name called a namespace.
For instance, if you are using the blog.posts collection in the dev database, the namespace of that collection would be Namespaces are limited to 121 bytes in length and, in practice, should be less than 100 bytes long.

Popular Posts