What Even is MongoDB

MongoDB is a Database Management System (DBMS). This means that it is a software which stores data in a database and allows one to interact with the data by changing it or displaying it.

MongoDB also makes use of the NoSQL principle to store its data. This means that each object which is stored within the database may have a different structure.

Architecture

MongoDB categorizes each database with a number of collections. A collection is the Relational Database equivalent of a table. So, for example, you would have a “Student” collection which groups all the data items defining students.

Each collection consist of a number of documents. Documents are the Relational Database equivalent of records. A single document in a Mongo Database is nothing more than a JSON object.

JSON

JSON (pronounced “Jason”) is an object oriented way of representing data. The main concept is that an object is between curly braces “{}” and properties of this object are a set of key/value pairs.

For example:

{
	student_number: 415324,
	name: "Susan",
	surname: "Strong",
	does_dancing: "yes",
	has_work_experience: "no"
}

The JSON above is a representation of a single object. This object properties various properties. One of these properties is a “name” and the value of the name is “Susan.”

It is also possible to have more than one of these objects at a time. This is called an array of objects, and the way which it is represented is with square brackets “[ ] “. Each object is separated by commas. See below an example of two student objects in the same array.

[
	{
		student_number: 415324,
		name: "Susan",
		surname: "Strong",
		does_dancing: "yes",
		has_work_experience: "no"
	},
	{
		student_number: 9826421,
		name: "John",
		surname: "Smith",
		supervisor: "Prof Clev R. Guy",
		beers_per_day: 3
	}

]

GeoJSON

When it comes to Geographical information, a special form of JSON is used by MongoDB to store the data. This standard is called GeoJSON. This is what it would look like:

{  
   "_id":"5cc1a372c8821f2d36c0ff23",
   "type":"Feature",
   "properties":{  
      "is_road" : "yes",
      "is_restaurant" : "no"
      "name" : "Some Main Highway"
   },
   "geometry":{  
      "type":"LineString",
      "coordinates":[  
         [  
            24.90006459611627,
            -25.894381996640988
         ],
         [  
            24.9012897961161,
            -25.894498096640962
         ],
         [  
            24.905121396115568,
            -25.895321796640868
         ]
      ]
   }
}

The part which makes this JSON object a GeoJSON object is the “geometry” part. It always has a type such as LineString, Point, Polygon, etc.

There is also a list of coordinates which are an array of latitudes and longitudes.

What Even is NoSQL

To understand what NoSQL is, it is needed to understand what Relational Database Management systems (RDBM) are. Basically, NoSQL databases are the next step in an evolution process of how computers stores and works with data.

Relational DBMS

A Relational Database Management system is a way of structuring any data and storing it in a database. It is the first attempt for people to organize their data in a logical way instead of just dumping everything as is.

Structure

The main principle of an RDBMS is the idea that each real-world entity is stored in a “Table.” Each table has a definite set of properties called columns. These set of properties define a single instance of an entity.

Here is an example of the data of two students stored in one table. The defined set of properties in this case is composed of student number, the student’s name and surname, age, course, as well as

Student No.NameSurnameAgeCourse
4 153 234SusanStrong21BSc Math
9 826 421JohnSmith22General BA

What even is SQL

SQL or Structured Query Language is a set of commands which allows one to interact with a Relational database. One can get the data, as well as change the data in the database using this language.

For example, the following SQL “Query” shows the user what data is in the Student table:

SELECT Name, Surname, Age FROM Student;

NoSQL Databases

NoSQL databases, that is “Not Only SQL,” as opposed to “No SQL,” differ in the sense that they have no specific structure for each entity.

Structure

Here is an example of two different students in a NoSQL Database

[
		{
				student_number: 415324,
				name: "Susan",
				surname: "Strong",
				does_dancing: "yes",
				has_work_experience: "no"
		},
		{
				student_number: 9826421,
				name: "John",
				surname: "Smith",
				supervisor: "Prof Clev R. Guy",
				beers_per_day: 3
		}

]

As you can see, the structure is quite different. At first glance, it may look difficult to understand, but please bear with me. There are two different students being described here, namely Susan and John.

The important thing to notice is that John does not have the “does_dancing” part, and Susan does not have a “supervisor.” So each student can have a different set of properties which described it. There is no single structure which describes all students.

Query Language

Because NoSQL is so different from the original Relational database systems, it cannot rely only on the standard language of SQL to interact with the data.

Design a site like this with WordPress.com
Get started