Tags

, , ,

What is MongoDB?
I saw many forums, visited many blogs, people/programmers are talking about MongoDB a lot. I was wondering what this is! Why developers are showing more and more interest in this. I started searching around and now sharing with all of you, who are not friendly with MongoDB or who’re familiar but don’t know how to work on it.

First of all let’s define mongoDB in terms of technical aspect
a) MongoDB has collections of data, not tables.
b) Its a document-oriented database.
c) MongoDB has namespaces for data.
d) You don’t ever need to worry about migrations due to Mongo’s schema-less nature.
e) You can define indexing options too.

So far, what my learning works here that it has nothing to do with the migrations, tables. In short if I say, it is a database in a documented form, a separate entity as compared to MySQL or different databases, am I wrong?

Ok, try to put your brain to understand this, because from here I will try to cover some real world examples to explain how it works… :)

How to install MongoDB
A) gem install mongo
It will install mongo with bson.. something like this screenshot

<image comes here />

B) gem install mongo_mapper

I think, these two gems are sufficient to give you some kind of acceleration. Let’s proceed further and create a model, fire this command
C) ruby script/generate model Book –skip-migration

<image comes here />

D) Let’s enter some fields into it, as I said it has nothing to do with the migration, so what are the columns that we want, we will create here itself, See how:

<image comes here />

Advertisements