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/
- Connect to your machine via Putty.
- Server IP – 127.0.0.1 & Port- 2222
- Username – root & default password – hadoop
- cd /etc/yum.repos.d/
- vi mongodb-org-4.2.repo
- 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
- Install the MongoDb packages.
sudo yum install -y mongodb-org
- Start MongoDb service.
Service mongod restart
- Check MongoDb version.
mongod –version
- 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
- Find the employee where id = 101
db.employee.find({“id”:”101″}).pretty()
- And operator in find query : where id =102 and name = dhruva
db.employee.find({$and:[{“id”:”102″},{“name”:”dhruva”}]}).pretty()
- Update document (Name updated from Ravi Kumar to Ravi Kumar shrivastav)
db.employee.update({“name”:”Ravi Kumar”},{$set:{“name”:”Ravi Kumar shrivastav”}})
- Delete document
db.employee.remove({“id”:”102″})
- Filtering & Sorting of data in desc order.
db.employee.find({},{“id”:1,”name”:3,_id:0}).sort({“id”:-1})