How to Install Mongodb on Ubuntu -Step by Step
In this tutorial, we will learn to install MongoDB on Ubuntu.
MongoDB is an opensource NoSQL database that keeps data as Jason-like structure, unlike SQL database that stores data in table structure.It provides high availability with replica sets.It scales horizontally using sharding.It can be used as a file system, called GridFS.
Also Read: How to install Anaconda on Linux
&& 15 Important PostgreSQL commands you must know
Install MongoDB on Linux(Ubuntu) using Apt Manager
Step 1– Update and upgrade your Ubuntu Box
$ sudo apt update && sudo apt upgrade -y
Step 2– Install MongoDB on Ubuntu
$ sudo apt-get install mongodb -y
Step 3- Check status of Mongo service.
$service mongodb status
You can also check the process and configuration file path by using following command
$ps -ef | grep mongodb
Use the following command to stop and start or restart the service
$ service mongodb start
$service mongodb stop
$service mongodb restart
Step 4- Connect Mongodb
Connect the database by using the following command
$mongo
Check Mongodb Version
$mongo -version
Some Basic Commands
Following are the basic commands that you must know
1) To show all databases
> show dbs ;
2) create a database or switch to already created databases
> use my-db;
Note: This DB will not show in show dbs; command until we do not insert any data in this.
3) Insert data into the newly created database.
$ db.Any data that represents your collection .insert({“data you want “:”value of the data”})
> db.names.insert({“username_name”:”chandan”})
4) show your collections
> show collections;
5) Delete your collections
db.name of your collection.drop();
> db.”names”.drop() ;
6) Drop the database
Make sure to switch to the database you want to delete and run the following command.
> db.dropDatabase() ;
I hope you enjoyed this tutorial and learned to Install MongoDB on Ubuntu. If you think this is helpful, please do share this post with others. Please also share your valuable feedback, comment or any query in the comment box. I will really happy to resolve your all queries.
Thank You
If you think we helped you or just want to support us, please consider these:-
Connect to us: Facebook | Twitter