Introducing a huMONGOus Database
Nowadays archiving, searching and processing the explosion of data generated in applications means coming up with nontraditional ways of dealing with the data. NoSQL solutions offer intriguing and unique ways of handling the volumes of data available to us. Additionally, 10Gen offers an open source distributed document-oriented solution called MongoDB. MongoDB straddles the NoSQL space nicely. A low barrier to entry and great performance help MongoDB continue to gain followers. However, like all database solutions, MongoDB will not solve all of your problems. You need to know when and how to use it properly and more importantly, when not to use it. Oddly Familiar MongoDB stores your data in documents using a JSON-style syntax known as BSON (binary JSON) making it a part of the document-oriented class of NoSQL solutions. | " | “MongoDB is considered a document-oriented datastore and it stores those documents in a JSON-style syntax called BSON (binary json).”
| " |
Document-oriented solutions can take some getting used to. Traditional RMDBS systems house their data in very well-defined schemas which are represented as tables. Each table definition is comprised of various columns which effectively define the data model in that RMDBS system. Each time data is inserted into a table, a new row is created. This data can be queried, updated, deleted and inserted using Structured Query Language (SQL). MongoDB, on the other hand, does not store its data in tables; MongoDB stores its data in collections. MongoDB collections are comprised of JSON documents instead of rows. Documents consist of key/value pairs - essentially a JSON hash. Unlike traditional RDMBS systems which adhere to a strict data schema, Mongo does not have a strict data schema. MongoDB doesn’t care if you have a key/value pair in one document but not in another. Each document can contain its own data structure (if needed) in the same collection. See Listing 1 for an example of the flexibility in action. An example of schemaless flexibility, Listing 1 has four MongoDB documents that reside in the same collection. Each document has an _id and name key, but the similarities stop there. A couple of documents contain a platform key. One document has a Twitter key and some have operating_system and homepage keys.
A powerful command-line shell comes bundled with MongoDB. You use the MongoDB shell for managing the server, setting up authentication and everything else you need. Third-party graphical administration tools do exist for MongoDB and you’ll find them at http://www.mongodb.org/display/DOCS/Admin+UIs. These tools provide quick lookup and management capabilities for your MongoDB system. MongoDB uses JavaScript in the MongoDB shell. Everything done in the shell will be JavaScript. When you enter a command without the parenthesis the code for the command displays. Having the ability to use JavaScript can be really powerful whether you are writing MapReduce queries or creating custom functions you want to use in the shell. Installation This article uses Mongo 2.0.2 for all of the examples, but anything over 2.x should work. You can download the latest version from http://www.mongodb.org/downloads. The MongoDB shell that comes bundled in the download will be sufficient for all examples. After downloading and unzipping the binary you will need to create a path for the data to be stored. The default location is /data/db. MongoDB does not create this directory, so you need to create it yourself. After you’ve created the directory you can start MongoDB by simply calling: /path/to/mongofiles/bin/mongod
If the installation went as it should, MongoDB is running and the real fun begins. |