Mongodb basic command
This blog and in upcoming blog we will see
mongodb basic and how is it work with installation and after
installation we should not face any problem while making Database, collection(table) and using the data in nodejs even whenever we will make
API.
-
# How to insert Data collection
-
# How to check inserted Data
- # How to update Data
- # How to delete Data
Now in this blog we will consider about mongoDB basic command which we can use
to create Database, collection etc.
What is MongoDB
MongoDB is a popular open-source NoSQL (non-relational) database management system. NoSQL means no structure like it is look like an object while in SQL it is a structure query language like SELECT CustomerName, City FROM Customers; (The SELECT statement is used to select data from a database.) But NoSQL database is useless...NOT completely because of whenever we want add extra column in database then it is possible through NoSQL MongoDB.
MongoDB installation - CLICK HERE
MongoDB Basic Command - CLICK HERE
About MongoDB vs SQL - CLICK HERE
How to insert Data collection
First we will open MongoDB compass tool actually mongodb compass tool is a only tool, it is used for only provid graphical user interface with CLI. Like how to insert, update, delete etc.
Even you can use mongodb in GUI or CLI mode but moslty beginner will using GUI (mongodb compass tool). So, we will start from mongodb start and stop command in command prompt windows.
net start MongoDB
net stop MongoDB
After starting mongoDB server and you can use this URL mongodb://localhost:27017 for connecting nodejs.we will make Database and collection Name.
Successfully created but there is no any data yet becuase of we have
just created the Database and its collection.
You can insert the data via when click on ADD DATA menu and choose option "insert document" and through mongosh CLI mode. But we will go to CLI mode okay!
-
# For choosing DB -
use database Name - (replace database name with text)
- # For insert One Data - db.student.insertOne({name: "atul", class: "one", rollno: 5})
For refresh this data in mongoDB (click on refresh button)
With GUI you can insert the data like this
You can view the data with three types.
You can also view the data via Mongosh CLI
- # Check data - db.student.find()
- # vcheck data with particular (_id) - db.student.find({_id : ObjectId("65a784b27d0ea65b469356c6")});
How to update Data
we will update the data whenever we want to change the data OKAY! but we will explore through mongosh CLI because you easily update with GUI.
- # For update data with particular _id - db.student.updateOne({_id: ObjectId("65a784b27d0ea65b469356c6")}, {$set: {name: "kumar atul jaiswal"}})
Here, first parameter (_id) is a condition like through
which do you want to update the data and second parameter is {$set)
that's mean what do you want to update like name, class, whatever name has
defined in your mongoDB collection's data. Even if
you want update the data through name you can. okay!
How to delete Data
Through this delete , it might be coming to your mind to delete any data. Hahah Lol! actually you're right.
Let's do it with CLI mode but you can easily go through GUI mode.
- # Delete data via name - db.student.deleteOne({name: "atul"})
NOTE - keep in mind that this is completely case sensitive, so whenever you enter any parameter or value, write it carefully.
Disclaimer
All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.
0 comments:
Post a Comment
For Any Tech Updates, Hacking News, Internet, Computer, Technology and related to IT Field Articles Follow Our Blog.