Monday, January 15, 2024

Day 28 || Introduction to MongoDB || Setting up MongoDB || CRUD operations with MongoDB

MongoDB Topics

Day 28:

  •  Introduction to MongoDB
  •  Setting up MongoDB
  •  CRUD operations with MongoDB


 Introduction to MongoDB:















Setting up MongoDB:


















CRUD operations with MongoDB:













To read:
show databases
show collections

Create collection:
use HemaDatabase
db.createCollection('HemaCodingSchool')
db.HemaCodingSchool.insertOne({ name: 'Mahesh', role: 'Student'})

-------------------------------------------
Create: 
db.HemaCodingSchool.insertOne(
{ name: 'Mahesh', role: 'Student' }
)
-------------------------------------------
Read:
db.HemaCodingSchool.find({})
-------------------------------------------
Update:
db.HemaCodingSchool.updateOne(
{ name: 'Mahesh'}, {$set:{ role: 'Emloyee'}} 
)
-------------------------------------------
Delete:
db.HemaCodingSchool.deleteOne({name: 'Mahesh'})

==============================================
Create Many: 

db.HemaCodingSchool.insertMany([
  { name: 'Hema', role: 'Organizer' },
  { name: 'Mahesh', role: 'Employee' },
  { name: 'Maruthi', role: 'Student' }
])

------------------------------------------------------
Update Many:

db.HemaCodingSchool.updateMany(
  { name: { $in: ['Hema', 'Mahesh', 'Maruthi'] } },
  { $set: { role: 'NewRole' } }
)

---------------------------------------------
Delete Many:

db.HemaCodingSchool.deleteMany(
  { name: { $in: ['Hema', 'Mahesh', 'Maruthi'] } }
)


Interview Questions: 

1. What is a Collection in MongoDB?

2. How do you insert a document in MongoDB?

3. Explain the $set operator in MongoDB?

No comments:

Post a Comment

Top 10 | JavaScript Coding Interview Question | Beginner Level

               JavaScript Coding Interview  Q. No. 01/10:  console . log ( "1" + "4" + "1" ) // 141 console . ...