MongoDB non-relational DB basics

MongoDB logo

A brief introduction to MongoDB

MongoDB is a non-relational database manager which stores records as JSON objects. MongoDB is also known as Document Oriented DB. All official documents can be found in MongoDB official page.

This feature gives the following advantages:

  • The Documents (objects or DB records), as they are JSON objects, correspond to data types in, for example, Javascript. This will make the queries faster and a unique representation of the data in our entire APP.
  • Embedded documents (one record can have an array as one of their fields or properties).  This have the advantage that you can save doing huge JOINS.
  • The DB schema is polymorph or dynamic. What does this mean? This means that a DB record must have different number of fields that another record, although they correspond with the same entity. This is also known as “schema-less”.
  • The documents are grouped into collections and, as the documents they contain are polymorph, they don’t have a rigid structure and allow any kind of documents (well, not any kind, but we’ll see later). The mongodb collection/document/field corresponds to table/row/column in another DB systems.

The applications communicate with MongoDB through Drivers. This drivers are the way MongoDB communicate with the main languages used on the web world. There are several drivers available for the main web application environments, and can be found in the official drivers page.

Example of document

Lets see an example of DB modeling with MongoDB. We need to store the information about our web application users. We may do this design:

_id: "joe",
name: "Hans",
lastname: "Baker"
address: {
street: "123 Long Road Street",
city: "New Town",
state: "ZY",
zip: "55555"

In this example, you can see the embedded data in a typical MongoDB structure.

In other posts I will go deep in the MongoDB basics.



  • Share post

One comment

Leave a Reply

Your e-mail address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.