Introduction to MongoDB

Ramit Malhotra

ramit@ischool.berkeley.edu

School of Information, UC Berkeley

What is Mongo?

"MongoDB is a document database that provides high performance, high availability, and easy scalability. Document Database. Documents (objects) map nicely to programming language data types. Embedded documents and arrays reduce need for joins."

.... I'm sorry..WHAT?!
MongoDB is an open-source document database, and leading NoSQL database.

Installing MongoDB

MongoDB vs RDBMS

  1. Schema less: MongoDB is document database in which one collection holds different different documents. Number of fields, content and size of the document can be differ from one document to another.
  2. Structure of a single object is clear
  3. No complex joins
  4. Deep query-ability. MongoDB supports dynamic queries on documents using a document-based query language that's nearly as powerful as SQL
  5. Ease of scale-out: MongoDB is easy to scale
  6. Conversion / mapping of application objects to database objects not needed
  7. Uses internal memory for storing the (windowed) working set, enabling faster access of data

Mongo 101: Why and Where?

Why should I use MongoDB?

Where should I use MongoDB?

Considerations

Example!

Suppose a client needs a database design for his blog website and see the differences between RDBMS and MongoDB schema design. Website has the following requirements.

RDBMS vs Mongo

The RDBMS way!

The MongoDB way!

{
   _id: POST_ID
   title: TITLE_OF_POST, 
   description: POST_DESCRIPTION,
   by: POST_BY,
   url: URL_OF_POST,
   tags: [TAG1, TAG2, TAG3],
   likes: TOTAL_LIKES, 
   comments: [	
      {
         user:'COMMENT_BY',
         message: TEXT,
         dateCreated: DATE_TIME,
         like: LIKES 
      },
      {
         user:'COMMENT_BY',
         message: TEXT,
         dateCreated: DATE_TIME,
         like: LIKES
      }
   ]
}
      	

So how do we use this thing?

Basic commands to get you started!

(contd) So how do we use this thing?

More commands..

(contd) So how do we use this thing?

And more commands..

Demo and Resources