SlideShare a Scribd company logo
• Server starting command :
-To start the client :
D:mongodbsetup software with guimongo 8mongosh-2.3.1-
win32-x64bin>mongosh.
-This command runs the MongoDB shell (modern shell: mongosh) from the
specified directory.
-What Happens Next:
-After execution, you are connected to the MongoDB instance running
on your system (usually localhost:27017 by default).
-You'll see a shell prompt where you can execute MongoDB
commands.
D:mongodbsetup software with guimongo 8mongosh-2.3.1-
win32-x64bin>mongosh
• Arepresentationofthe serverstarting—
Importing the data—
-ToimporttheJsonfile-
-Purpose:ImportsdataintoMongoDBfromafile.
-Key Options:--db:Specifiesthe database (test).
--collection:Specifiesthe collection (movie).
--file:Path tothe inputfile (movie.json).
ExampleUse:InsertsJSONdataintothe movie collection inthe test
database.
D:mongodbmongodb-database-tools-windows-x86_64-
100.8.0bin>mongoimport --db test -- collection movie --file D:
mongodbJsonFilesmovie.json
• A representationofthe Importingdata—
Exporting the data—
-Toexportthe Json file-
-Purpose:ExportsdatafromMongoDBtoafile.
-Key Options:--db:Specifiesthe database (test).
--collection:Specifiesthe collection(movie).
--out:Pathtosave the exported file (mymovie.json).
Example Use:Extractsalldocumentsfromthemoviecollection in
the testdatabaseand savesthemin JSONformat.
D:mongodbmongodb-database-tools-windows-x86_64-
100.8.0bin>mongoexport --db test -- collection movie --out
D:mongodbJsonFilesmymovie.json
To create a collection—
-ToCreate anewcollection--
-Purpose:Createsanewcollection explicitly in the currentdatabase.
KeyNotes:MongoDBautomaticallycreatescollectionswhen inserting documents.
Use createCollection foradvancedconfigurations(e.g.,capped collections).
Example Use:Createsacollection named newCollection.
Test>db.createCollection(“newCollection”)
• A representationofcreatingacollection—
Inserting a record—
-ToInsertasingle record in the collection
db.movie.insertOne({
title: "The Matrix",
year: 1999,
genre: "Sci-Fi",
director: "Lana Wachowski, Lilly Wachowski",
rating: 8.7,
cast: ["Keanu Reeves", "Laurence Fishburne", "Carrie-Anne
Moss"]
});
• ArepresentationofInsertingarecord—
A little about insertion query
-Purpose:Insertsasingle documentintothe movie collection.
-Key Fields:title:Movie title.
year:Release year.
genre:Movie genre.
director:Director(s) ofthemovie.
rating:IMDb rating.
cast:Listofmainactors.
ExampleUse:Addsadocumentwithmovie detailsintothemovie
collection.
-Inthesame waywe canaddmultiple recordsusing(“insertMany”)command.
Displaying a record—
-ToDisplayasingle recordinthe collection
-Purpose:Retrievesasingle documentfromacollectionthatmatchesthequery
criteria.
-Parameters:
-query:Criteriatomatch the document(e.g.,{title:"TheMatrix"}). -
-projection:Specifieswhich fieldstoincludeorexclude(e.g.,{title:1,year:1,
_id:0}).
-ExampleUse:Findsthefirstdocumentmatchingthe queryandreturnsspecified
fields.
db.collection.findOne(query, projection);
• ArepresentationofDisplayingarecord—
Deleting a record—
-ToDeleteasingle recordinthecollection
-Purpose:Deletesasingle documentfromacollectionthatmatchesthequery
criteria.
-Parameters:
-query:Criteriatofindthedocumenttodelete (e.g.,{title:"TheMatrix"}). -
Example Use:Deletesthe firstdocumentthatmatchesthe specifiedquery.
-We canalsodeletemanyrecordatonce using“db.movie.deleteMany({});”
db.collection.deleteOne(query);
• ArepresentationofDeletingarecord—
Updating a record—
-ToUpdatearecord in the collection
-Purpose:Updatesasingledocumentinacollection thatmatchesthe query
criteria.
-Parameters:
-query:Criteriatofindthedocument(e.g.,{title:"The Matrix"}).
-update:Theupdateoperation toperform(e.g.,{$set:{rating:9.0}}).
-options:Optionalsettings(e.g.,{upsert:true }toinsertthedocumentifit
doesn’texist).
-ExampleUse:Updatesthe firstdocumentmatchingthe query,settinganew
rating.
db.collection.updateOne(query, update, options);
• ArepresentationofUpdatingarecord—
Using Group By —
-Touse groupbyinthecollection
-Purpose:Performsadvanceddataaggregation,such asgroupingand
summarizingdata.
-Key Stage($group):Groupsdocumentsby afieldorexpressionand applies
accumulatorslike $sum,$avg,$count,etc.
-Parameters:_id:Fieldtogroupby(e.g.,"$genre").
<field>:Name oftheoutputfield.
<accumulator>:Aggregationfunction(e.g.,$sum,$avg).
db.collection.aggregate([
{ $group: { _id: <expression>, <field>: { <accumulator>:
<expression> } } }
]);
• ArepresentationofGroupby—
Using Join—
-Touse Join inthe collection
db.collection.aggregate([
{
$lookup: {
from: "<foreign_collection>",
localField: "<local_field>",
foreignField: "<foreign_field>",
as: "<output_field>"
}
}
]);
A little about Join / Lookup—
-Purpose:Performsaleftouterjointocombinedocumentsfromtwocollections.
-Key Fields:from:Nameofthe collectiontojoin with.
-localField:Fieldinthe currentcollection tomatch.
-foreignField:Fieldinthe foreigncollectiontomatch.
-as:Nameofthe arrayfieldtostorethejoineddata.
• ArepresentationofJoin--
Ad

More Related Content

Similar to MongoDb implementation and screenshots for easier understanding (20)

Getting started with replica set in MongoDB
Getting started with replica set in MongoDBGetting started with replica set in MongoDB
Getting started with replica set in MongoDB
Kishor Parkhe
 
오픈 소스 프로그래밍 - NoSQL with Python
오픈 소스 프로그래밍 - NoSQL with Python오픈 소스 프로그래밍 - NoSQL with Python
오픈 소스 프로그래밍 - NoSQL with Python
Ian Choi
 
MongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL DatabaseMongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL Database
FITC
 
Webinar slides: How to Secure MongoDB with ClusterControl
Webinar slides: How to Secure MongoDB with ClusterControlWebinar slides: How to Secure MongoDB with ClusterControl
Webinar slides: How to Secure MongoDB with ClusterControl
Severalnines
 
Mongodb replication
Mongodb replicationMongodb replication
Mongodb replication
PoguttuezhiniVP
 
Windows containers troubleshooting
Windows containers troubleshootingWindows containers troubleshooting
Windows containers troubleshooting
Alexey Bokov
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
 
Node.js
Node.jsNode.js
Node.js
krishnapriya Tadepalli
 
How To Build and Run Node Apps with Docker and Compose
How To Build and Run Node Apps with Docker and ComposeHow To Build and Run Node Apps with Docker and Compose
How To Build and Run Node Apps with Docker and Compose
Docker, Inc.
 
Install nagios
Install nagiosInstall nagios
Install nagios
hassandb
 
Install nagios
Install nagiosInstall nagios
Install nagios
hassandb
 
Install nagios
Install nagiosInstall nagios
Install nagios
hassandb
 
MongoDB Command Line Tools
MongoDB Command Line ToolsMongoDB Command Line Tools
MongoDB Command Line Tools
Rainforest QA
 
Mongodb tutorial by Rajendra Arora
Mongodb tutorial by Rajendra AroraMongodb tutorial by Rajendra Arora
Mongodb tutorial by Rajendra Arora
Rajendra Arora
 
Prosit google-cloud
Prosit google-cloudProsit google-cloud
Prosit google-cloud
UC Davis
 
Mongo db roma replication and sharding
Mongo db roma replication and shardingMongo db roma replication and sharding
Mongo db roma replication and sharding
Guglielmo Incisa Di Camerana
 
Setting up mongodb sharded cluster in 30 minutes
Setting up mongodb sharded cluster in 30 minutesSetting up mongodb sharded cluster in 30 minutes
Setting up mongodb sharded cluster in 30 minutes
Sudheer Kondla
 
Howto Pxeboot
Howto PxebootHowto Pxeboot
Howto Pxeboot
Rogério Sampaio
 
Owning computers without shell access 2
Owning computers without shell access 2Owning computers without shell access 2
Owning computers without shell access 2
Royce Davis
 
Designate Installation Workshop
Designate Installation WorkshopDesignate Installation Workshop
Designate Installation Workshop
Graham Hayes
 
Getting started with replica set in MongoDB
Getting started with replica set in MongoDBGetting started with replica set in MongoDB
Getting started with replica set in MongoDB
Kishor Parkhe
 
오픈 소스 프로그래밍 - NoSQL with Python
오픈 소스 프로그래밍 - NoSQL with Python오픈 소스 프로그래밍 - NoSQL with Python
오픈 소스 프로그래밍 - NoSQL with Python
Ian Choi
 
MongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL DatabaseMongoDB: Advantages of an Open Source NoSQL Database
MongoDB: Advantages of an Open Source NoSQL Database
FITC
 
Webinar slides: How to Secure MongoDB with ClusterControl
Webinar slides: How to Secure MongoDB with ClusterControlWebinar slides: How to Secure MongoDB with ClusterControl
Webinar slides: How to Secure MongoDB with ClusterControl
Severalnines
 
Windows containers troubleshooting
Windows containers troubleshootingWindows containers troubleshooting
Windows containers troubleshooting
Alexey Bokov
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
 
How To Build and Run Node Apps with Docker and Compose
How To Build and Run Node Apps with Docker and ComposeHow To Build and Run Node Apps with Docker and Compose
How To Build and Run Node Apps with Docker and Compose
Docker, Inc.
 
Install nagios
Install nagiosInstall nagios
Install nagios
hassandb
 
Install nagios
Install nagiosInstall nagios
Install nagios
hassandb
 
Install nagios
Install nagiosInstall nagios
Install nagios
hassandb
 
MongoDB Command Line Tools
MongoDB Command Line ToolsMongoDB Command Line Tools
MongoDB Command Line Tools
Rainforest QA
 
Mongodb tutorial by Rajendra Arora
Mongodb tutorial by Rajendra AroraMongodb tutorial by Rajendra Arora
Mongodb tutorial by Rajendra Arora
Rajendra Arora
 
Prosit google-cloud
Prosit google-cloudProsit google-cloud
Prosit google-cloud
UC Davis
 
Setting up mongodb sharded cluster in 30 minutes
Setting up mongodb sharded cluster in 30 minutesSetting up mongodb sharded cluster in 30 minutes
Setting up mongodb sharded cluster in 30 minutes
Sudheer Kondla
 
Owning computers without shell access 2
Owning computers without shell access 2Owning computers without shell access 2
Owning computers without shell access 2
Royce Davis
 
Designate Installation Workshop
Designate Installation WorkshopDesignate Installation Workshop
Designate Installation Workshop
Graham Hayes
 

Recently uploaded (20)

Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
Mental Health Assessment in 5th semester bsc. nursing and also used in 2nd ye...
parmarjuli1412
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
Ad

MongoDb implementation and screenshots for easier understanding

  • 1. • Server starting command : -To start the client : D:mongodbsetup software with guimongo 8mongosh-2.3.1- win32-x64bin>mongosh. -This command runs the MongoDB shell (modern shell: mongosh) from the specified directory. -What Happens Next: -After execution, you are connected to the MongoDB instance running on your system (usually localhost:27017 by default). -You'll see a shell prompt where you can execute MongoDB commands. D:mongodbsetup software with guimongo 8mongosh-2.3.1- win32-x64bin>mongosh
  • 3. Importing the data— -ToimporttheJsonfile- -Purpose:ImportsdataintoMongoDBfromafile. -Key Options:--db:Specifiesthe database (test). --collection:Specifiesthe collection (movie). --file:Path tothe inputfile (movie.json). ExampleUse:InsertsJSONdataintothe movie collection inthe test database. D:mongodbmongodb-database-tools-windows-x86_64- 100.8.0bin>mongoimport --db test -- collection movie --file D: mongodbJsonFilesmovie.json
  • 4. • A representationofthe Importingdata—
  • 5. Exporting the data— -Toexportthe Json file- -Purpose:ExportsdatafromMongoDBtoafile. -Key Options:--db:Specifiesthe database (test). --collection:Specifiesthe collection(movie). --out:Pathtosave the exported file (mymovie.json). Example Use:Extractsalldocumentsfromthemoviecollection in the testdatabaseand savesthemin JSONformat. D:mongodbmongodb-database-tools-windows-x86_64- 100.8.0bin>mongoexport --db test -- collection movie --out D:mongodbJsonFilesmymovie.json
  • 6. To create a collection— -ToCreate anewcollection-- -Purpose:Createsanewcollection explicitly in the currentdatabase. KeyNotes:MongoDBautomaticallycreatescollectionswhen inserting documents. Use createCollection foradvancedconfigurations(e.g.,capped collections). Example Use:Createsacollection named newCollection. Test>db.createCollection(“newCollection”)
  • 8. Inserting a record— -ToInsertasingle record in the collection db.movie.insertOne({ title: "The Matrix", year: 1999, genre: "Sci-Fi", director: "Lana Wachowski, Lilly Wachowski", rating: 8.7, cast: ["Keanu Reeves", "Laurence Fishburne", "Carrie-Anne Moss"] });
  • 10. A little about insertion query -Purpose:Insertsasingle documentintothe movie collection. -Key Fields:title:Movie title. year:Release year. genre:Movie genre. director:Director(s) ofthemovie. rating:IMDb rating. cast:Listofmainactors. ExampleUse:Addsadocumentwithmovie detailsintothemovie collection. -Inthesame waywe canaddmultiple recordsusing(“insertMany”)command.
  • 11. Displaying a record— -ToDisplayasingle recordinthe collection -Purpose:Retrievesasingle documentfromacollectionthatmatchesthequery criteria. -Parameters: -query:Criteriatomatch the document(e.g.,{title:"TheMatrix"}). - -projection:Specifieswhich fieldstoincludeorexclude(e.g.,{title:1,year:1, _id:0}). -ExampleUse:Findsthefirstdocumentmatchingthe queryandreturnsspecified fields. db.collection.findOne(query, projection);
  • 13. Deleting a record— -ToDeleteasingle recordinthecollection -Purpose:Deletesasingle documentfromacollectionthatmatchesthequery criteria. -Parameters: -query:Criteriatofindthedocumenttodelete (e.g.,{title:"TheMatrix"}). - Example Use:Deletesthe firstdocumentthatmatchesthe specifiedquery. -We canalsodeletemanyrecordatonce using“db.movie.deleteMany({});” db.collection.deleteOne(query);
  • 15. Updating a record— -ToUpdatearecord in the collection -Purpose:Updatesasingledocumentinacollection thatmatchesthe query criteria. -Parameters: -query:Criteriatofindthedocument(e.g.,{title:"The Matrix"}). -update:Theupdateoperation toperform(e.g.,{$set:{rating:9.0}}). -options:Optionalsettings(e.g.,{upsert:true }toinsertthedocumentifit doesn’texist). -ExampleUse:Updatesthe firstdocumentmatchingthe query,settinganew rating. db.collection.updateOne(query, update, options);
  • 17. Using Group By — -Touse groupbyinthecollection -Purpose:Performsadvanceddataaggregation,such asgroupingand summarizingdata. -Key Stage($group):Groupsdocumentsby afieldorexpressionand applies accumulatorslike $sum,$avg,$count,etc. -Parameters:_id:Fieldtogroupby(e.g.,"$genre"). <field>:Name oftheoutputfield. <accumulator>:Aggregationfunction(e.g.,$sum,$avg). db.collection.aggregate([ { $group: { _id: <expression>, <field>: { <accumulator>: <expression> } } } ]);
  • 19. Using Join— -Touse Join inthe collection db.collection.aggregate([ { $lookup: { from: "<foreign_collection>", localField: "<local_field>", foreignField: "<foreign_field>", as: "<output_field>" } } ]);
  • 20. A little about Join / Lookup— -Purpose:Performsaleftouterjointocombinedocumentsfromtwocollections. -Key Fields:from:Nameofthe collectiontojoin with. -localField:Fieldinthe currentcollection tomatch. -foreignField:Fieldinthe foreigncollectiontomatch. -as:Nameofthe arrayfieldtostorethejoineddata.
  翻译: