RakDBA MongoDB Posts Getting started with MongoDB

Getting started with MongoDB

mongodb

Today, I want to share with you some of the basics stuff about MongoDB concept and commands, so If you are beginner to MongoDB, this article is recommended for you 😉


What is MongoDB !?

We can represent a MongoDB like a rich document-oriented NoSQL database that stores the data in the form of JSON documents with an autogenerated identified for every document. 

NoSQL ?? yes !! A No-SQL database is a database where the table structure is not fixed, unlike the structure of the Tables on SQL databases. 

So MongoDB stores the data in the form of JSON string irrespective of the count of attributes or names of attributes in a specific column. 

This allows developers to quickly make changes to entities without needing to change anything in the database level. And this is the great power of the NOSQL databases.

Following are some of the key points in MongoDB vs RDBMS which clearly show differences between MongoDB and RDBMS (SQL Databases):

RDBMSMongoDB
DatabaseDatabase
TablesCollections
RowsDocuments
ColumnsFields

Comparing to a typical relational database, this is how MongoDB database looks like  : 


MongoDB Server Versions :

ReleaseRelease DateEnd of Life Date
MongoDB 4.4July 2020---
MongoDB 4.2August 2019---
MongoDB 4.0June 2018January 2022
MongoDB 3.6November 2017April 2021
MongoDB 3.4November 2016January 2020
MongoDB 3.2December 2015September 2018
MongoDB 3.0March 2015February 2018
MongoDB 2.6April 2014October 2016
MongoDB 2.4March 2013March 2016
MongoDB 2.2August 2012February 2014
MongoDB 2.0
September 2011March 2013
MongoDB 1.8March 2011September 2012
MongoDB 1.6August 2010February 2012
MongoDB 1.4March 2010September 2012
MongoDB 1.2December 2009June 2011

Basic commands on mongo shell :

The following commands provides various examples for querying in the MongoDB shell.

  • Connect with “admin login” to “admin database” :
$ mongo admin -u admin -p admin_password

  • Show all available databases :
$ show dbs;

  • Access to a particular database, e.g. testdb . This will create testdb if it does not already exist:
$ use testdb;

  • Show all collections in the database :
$ show collections;

  • Create a new collection  :
$ db.createCollection('newCollection');

  • Insert document into the newCollection created above :
$ db.newCollection.insertOne({name:'Yad',age:'25'});

Operators on mongo shell :

The following operators are using for querying in the MongoDB shell :

OperatorUseExample
$eqCheck if the value is equal{age:{$eq:20}}
$ltCheck if value is less than{age: {$lt:20}}
$gteCheck if value is greater than or equal to{age:{$gte:22}}
$lteCheck if value is less thank or equal to{age:{$lte:22}}
  • Example :
$ db.newCollection.find({age:{$gt:20}});

{ "_id" : ObjectId("7b5c29a715b06e5e783d8453"), "name" : "Yad", "age" : 25 }

 

I hope now you know what MongoDB looks like, how documents are different compared to a typical relational database record, and you are able to do some manipulation on your MongoDB database. 

 

5 2 votes
Article Rating
Subscribe
Notify of
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments