Installation & Introduction to MongoDb – NOSql Database

MongoDb is a NOSQL database.

Once HDP Sandbox environment is available on your windows machine, let’s setup MongoDb Server on this virtual centOS machine.

To set up Hadoop Sandbox Environment on your windows machine – Follow the Steps in the post that we posted earier

https://instrovate.com/2019/10/12/hortonworks-hdp-sandbox-environment-a-complete-setup-guide/

  1. Connect to your machine via Putty.
  2. Server IP – 127.0.0.1 & Port- 2222
  3. Username – root & default password – hadoop
  4. cd /etc/yum.repos.d/
  5. vi mongodb-org-4.2.repo

  1. Paste the below repositories url in the .repo file.

[mongodb-org-4.2]

name=MongoDB Repository

baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/

gpgcheck=1

enabled=1

gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc

  1. Install the MongoDb packages.

sudo yum install -y mongodb-org

  1. Start MongoDb service.

Service mongod restart

  1. Check MongoDb version.

mongod –version

               

  1. Quick go-through commands to use database, insert and find objects in collection.

show dbs –  will show databases,

use instrovate_db  

db.employee.insert({“id”:”101,”name”:”Ravi Kumar”}) – to create and insert data in collection.

db.find.employee() – to list the data in collection

         

  1. Find the employee where id = 101

db.employee.find({“id”:”101″}).pretty()

  1. And operator in find query : where id =102 and name = dhruva

db.employee.find({$and:[{“id”:”102″},{“name”:”dhruva”}]}).pretty()

  1. Update document (Name updated from Ravi Kumar to Ravi Kumar shrivastav)

db.employee.update({“name”:”Ravi Kumar”},{$set:{“name”:”Ravi Kumar shrivastav”}})

 

  1. Delete document

db.employee.remove({“id”:”102″})

  1. Filtering & Sorting of data in desc order.

db.employee.find({},{“id”:1,”name”:3,_id:0}).sort({“id”:-1})