Getting Started with MongoDB
MongoDb is a No SQL Database, this means that we do not use SQL commands to interact with it. Unlike SQL databases that are made of Columns with Rows and on each Table consist rows that stores data types and each of the column is a property on the Table. Often times, tables can be related to each other using joins and we use SQL commands like:
SELECT * FROM authors;
To query all the records in the authors table.
A No SQL database like MongoDB is very different from a SQL database because instead of columns and rows , it uses what is known as collections or documents. Unlike SQL databases that use Tables and Rows, MongoDB records are called documents and they look very much like objects as they use Key-pair. These documents can have a few benefits over using columns and rows.
{
‘title’:'Animal World',
‘rating’: 9,
‘duration’: 400
}
It is much easy to work with this if you are using JavaScripts because documents are very much like json or javaScript objects.
Secondly, it allows us to store nested document within a document.
{
‘title’:'Animal World',
‘rating’: 9,
‘duration’: 400,
‘author’:{
‘firstname’:'…',
‘lastname’:'…'
}
}
Using a nested method will be an alternative to using 2 sql tables to store the data separately. You could also have 2 collections for data in MongoDB if you preferred. It has a high speed performance. MongoDB Installation Irrespective of the OS you are using, you need to download
MongoDB Community Server download here MongoDB Shell download here MongoDB Compass (GUI) download here After installation, to check if it was properly installed.
Open your terminal type mongosh
Current Mongosh Log ID: 62ff99d****30d185f0d****
Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000&appName=mongosh+1.5.4
Using MongoDB: 6.0.0
Using Mongosh: 1.5.4
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
------
The server generated these startup warnings when booting
2022-08-14T08:54:34.969+01:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted
------
------
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).
The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.
To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
------
test>
You should have a display of your mongoDB and Mongosh Version.