MongoDB
MongoDB is an open-source NoSQL database management program. NoSQL (Not only SQL) is used as an alternative to traditional relational databases. NoSQL databases are quite useful for working with large sets of distributed data. MongoDB is a tool that can manage document-oriented information, and store or retrieve information.
let's start
Open your "cmd", type "mongo" and run it.
How can we create the Database?
Syntax- use Database_Name
Example - use mydb
Now we have created a database
How can you create a collection in the database?
use db.createCollection("collection_name") command and create your collection
How can you see your collection?
use the "show collections" command and do it.
How can we insert the data into our collection?
You can use "db.student.insertOne({name: "Rahul", class: "11th", marks: 95});"
and insert your first data into your database.
And now, How can you find this data on your screen?
use "db.student.find()" and find your data in your screen
How can you update the data?
use "db.student.update({name:"Rahul"}, {$set:{name:"Rahul Kumar"}});" and update your data.
How can you delete the data?
use "db.student.remove({name: "Rahul Kumar"});" and delete your data.
How to add multiple records together?
to add multiple records at once in MongoDB we can use:
db.student.insertMany([{name: "Sarthak", class: "12th", marks: 89},
{name: "JD", class: "10th", phone: 9407064296},
{name: "ajay", class: "12th", marks: 87}])
Can we add an array in the JSON in MongoDB?
we can simply use [] to add an array:
use "db.student.insertOne({name: 'Anurag', subjects: ['web', 'javascript']});".
How to import sample DB in MongoDB?
To get some free sample datasets you can check out this GitHub link.