Overview Of NoSQL and MongoDB

Introduction to NoSQL and MongoDB

NoSQL is a concept for managing databases without the use of SQL(Structured Query Language). NoSQL database management systems have the unique advantage to scale horizontally(scale out), which means that they can work with huge amounts of data. This explains why these systems are used by companies such as Google, Facebook and Amazon to store data which cannot be feasibly stored in another manner.

Other differences between SQL and NoSQL is that the latter does not always require fixed table schemas or support join operations. Since NoSQL is not relational the principle of ACID(atomicity, consistency, isolation, durability) cannot be guaranteed. This makes NoSQL unpopular for storing data which requires normalization and consistency.

MongoDB (the name comes from "huMONGOus" and not from the movie Blazing Saddles) is a first class citizen(scalable, high performance and powerful) in the family of NoSQL systems. It is Open Source and free to use with enterprise support which the perfect combination for any needs from personal to corporate.

MongoDB specifics

  • A document is the basic unit of data in MongoDB similar to a row in relational databases. Every document has a specific unique field (key) called "_id".  
  • A collection contains documents and is the analog of a table. MongoDB does not impose schemas and fields data types restrictions on its collections. This does not mean that data types are not supported though.
  • MongoDB is case and type sensitive. 
  • Duplicate keys are not allowed, i.e. documents like these are not allowed: {"banner" : "MongoDB is perfect", "banner" : "MongoDB is imperfect"}

Installation and configuration of MongoDB

MongoDB offers both source package installation and binary packages for most popular Linux OSs. To install it on Redhat based operating systems you can use the the provider's repo. Once you have the MongoDB repo added run 'yum makecache' to download the headers for the available packages. Then install MongoDB's client and server by running in console 'yum install mongo-10gen mongo-10gen-server'.
Once yum confirms the successful installation of MongoDB you should add the server to the default runlevels by executing chkconfig mongod on to ensure that MongoDB's daemon will be started / shutdown automatically with the server. To start the daemon right away run 'service mongod start'.
The configuration of MongoDB can be found in the file /etc/mongod.conf. For a beginning the default options are good and can be left unchanged. If your server is not in a trusted environment, i.e. firewalled / private network and trusted local users, you should consider changing the directive 'auth = true' so that database use is not left without authentication.


Using MongoDB

Working with MongoDB is similar to working with other database services. It listens to a port, TCP 27017 by default, and you connect with the MongoDB client(/usr/bin/mongo). The client gives you an interactive text-based shell, similar to that for MySQL and PostgreSQL. This client is also a fully featured Javascript interpreter capable of running Javascript programs. To get started try the command 'help' which gives you an idea of the basic commands and their usage.
> help
	db.help()                    help on db methods
	db.mycoll.help()             help on collection methods
	rs.help()                    help on replica set methods
	help admin                   administrative help
	help connect                 connecting to a db help
	help keys                    key shortcuts
	help misc                    misc things to know
	help mr                      mapreduce

	show dbs                     show database names
	show collections             show collections in current database
	show users                   show users in current database
	show profile                 show most recent system.profile entries with time >= 1ms
	show logs                    show the accessible logger names
	show log [name]              prints out the last segment of log in memory, 'global' is default
	use                 set current database
	db.foo.find()                list objects in collection foo
	db.foo.find( { a : 1 } )     list objects in foo where a == 1
	it                           result of the last line evaluated; use to further iterate
	DBQuery.shellBatchSize = x   set default number of items to display on shell
	exit                         quit the mongo shell
Assuming most readers are well acquainted with SQL here is SQL to Mongo Mapping Chart. It helps to start thinking in NoSQL language translating your SQL old habits. Except the command line MongoDB client there are also many other interfaces and applications to facilitate the work with MongoDB. Examples are the HTTP console and the REST interface. The REST interface is especially useful to streamline the management of the MongoDB data from other applications.
There are also popular applications supporting MongoDB such as MongoPress, an alternative to WordPress. Though the idea behind NoSQL and MongoDB is not to replace the traditional SQL systems because after all relations and SQL are not bad things. That's why it would make little sense to try using NoSQL where SQL would suit better such as IN small to middle sized blog and content management systems.
Instead MongoDB is much more suitable than SQL systems for dealing with large data such as logs. For this specific purpose there is a popular application called Graylog. It allows you to send various logs from various servers and services to a centralized storage based on MongoDB.


MongoDB fights its way in the very competitive NoSQL world where major players such as Amazon SimpleDB have predominant market positions. Though in some cases when you want to use your own environment and not Amazon's, MongoDB is a popular choice and its features will comply with most NoSQL application requirements.

blog comments powered by Disqus