MongoDB is a document-based non-relational database management system. It’s also called an object-based system. It offers faster query processing but with an increased load and system requirements.
In order to get started with Mongodb, you need to install Mongodb to your computer. To install the mongodb, you need to run this command.
sudo apt update
sudo apt upgrade
sudo apt install mongodb
#To check if the installation is successfullsudo systemctl status mongodb
#To restart mongodb servicesudo systemctl restart mongodb
#To stop mongodbsudo systemctl stop mongodb
#To uninstall mongodbsudo systemctl stop mongodb
sudo apt purge mongodb
- To open the MongoDB, run this command:
mongo
Mongodb command
Show database available
- To check the databases, type show databases; command
Create new database
- To add new database, type use <name_of_db>
Check db in use
- For checking what db in use, type db.
Add Collections
- To add collection in the database in use, type <name_of_db>.createCollection(“sample”)
Insert data
- To add data in the collection created, type <name_of_db>.<name_of_collection>.insert({name:”sample”})
Show data
- To show the data in the collection, type <name_of_db>.<name_of_collection>.find()
Update data
- To update data in collection, type <name_of_db>.<name_of_collection>.updateOne({<filter>},{<changes>}).
Note: This updateOne command only update the first data it reads, notice the first name with new_sample_name.
Delete data
- To delete a data in collection, type <name_of_db>.<name_of_collection>.updateOne({<filter_data_to_be_deleted>}
Note: This deleteOne command only deletes the first data it reads.
For more detailed mongodb command:
https://cheatography.com/isaeus/cheat-sheets/mongodb/