
Introduction
MongoDB is an open-source, document-oriented database and leading NoSQL database. It is written in C++. It provides high performance, high availability, and easy scalability. MongoDB works on the concept of collections and documents. It is a popular database that has been popular for several years. In this blog, we can check different aspects of MongoDB.
Document Oriented Database
This is certainly the foremost. MongoDB is a database. That means, is a collection of data that facilitates easy access and update. MongoDB is a NoSQL / document oriented database. This means it is not a traditional structured database that stores data in formal tables and columns. Instead, it stores data in an unstructured form, as a collection of documents. Now what is the big deal? Is unstructured data more efficient? If that is the case, why did our ancestors take all the trouble of structuring data in form of tables? And if structuring was the right way to go, why is everyone moving to unstructured data? How can both be correct? Has something changed?
Yes a lot has changed. The data has changed. The volume of data has changed. The velocity of data has changed. The variety of data has changed. On the other hand, storage capacity, processing power as well as the search algorithms have changed. Because of slow velocity and consistency of the data being pushed into the database; because of higher latency of the database search; it made more sense to keep the data well organized so that the search would be quick enough. Today, the extreme velocity, variety and volume of the data leave you no time to organize it. Also, the improved search process allows you to afford the unstructured storage.
In simple words - when search was a bottleneck all databases were implemented in a way that would organize the data in a way that facilitates faster search. Today, the bottleneck is in absorbing and streamlining the high volume, variety and velocity of the data being pumped into the database. Naturally the database implementations have changed.
Collections and Documents
MongoDB stores its data in form of collections and documents. A MongoDB database is a container of collections. Each database gets its own set of files on the file system. A single MongoDB server typically has multiple databases. Collection is a group of MongoDB documents. It is the equivalent of an RDBMS table. A collection exists within a single database. Collections do not enforce a schema. Documents within a collection can have different fields. Typically, all documents in a collection are of similar or related purpose.
A document is a set of key-value pairs. Documents have dynamic schema. Dynamic schema means that documents in the same collection do not need to have the same set of fields or structure, and common fields in a collection's documents may hold different types of data. Any sensible developer would create a collection out of related documents. Even if they do not follow the same syntactic schema, they would be functionally related. But MongoDB does not insist on any such restriction.
Mongo DB Installation
The community edition of MongoDB can be installed on Ubuntu or any Debian system using simple steps
Import the public key
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80Â --recv 0C49F3730359A14518585931BC711F9BA15703C6
Create List of files for MongoDB
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse"Â | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
(xenial for Ubuntu 16 - Use the appropriate path for your version of Ubuntu.)
Reload the package database
sudo apt-get update
Install the latest stable version of MongoDB
sudo apt-get install -y mongodb-org
And the server is ready on your machine.
The MongoDB Server
MongoDB runs as Linux service. It can be handled in Ubuntu like any other service.
sudo service mongod start
sudo service mongod stop
sudo service mongod restart
Uninstall MongoDB
If you are done with it and want to uninstall the MongoDB server, it is equally simple. First Stop the MongoDB service. Then remove any MongoDB packages that you have installed. And finally remove the database and log files.
sudo service mongod stop
sudo apt-get purge mongodb-org*
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
Kommentare