Experiment - &
PerformCRUD Operationson MongoDB usingCompass.
Step 1: MongoDB
Download and Install and MongoDB Compass from:.
[Link]
O Download MongoDs Commun
[Link]/try/download/community
Sign In Try Froo
Support
Products Solutionsv Company Pricing
Rosources
MongoDB.
MongoDB Atlas
MongoDB Enterprise
Version
Advanced
7.0.3(ourrent)
MongoDB Community
Edition
Platform
Windows x64
MongoDB Community
Server
Puokogo
MongoDB Community msi
Kubernetes Operator
Tools
Copy link More Options
AtlasSCL Interfaoe
Mobile& Edge
Step 2:Open MongoDB Compass and Clickon Connect to defaultURL.
4 MongoDB Compass
Connet Eda Viw
Help
Compass
New oonneotion
New Connection
FAVORITE
Connect to a MongoDB deployment
EditConnectionString
URI O
Saved connections
O
mongodb://looulhost:27017
Rocents
> Advanoed Conneotlon Options
Save Save & Connoct Connect
g
New to Compass and don'thave
oluster?
if don'alreodyhavea cluster,you con
you
creoteone forfreeusingMongoDB
Ailoe
CREATE FREECLUSTER
How do ifindmy oonnectionstring
ir
NV Polytechnic Page 28
Step 3:Clickon the + iconto createa database.
localhosti27017
0 My Queries
Databases
Search
admin
config
local
mydatabase
on Create Database.
Name and click
Step 4: Assignthe Database Name and Collection
CreateDatabase
Database Name
PerformingCRUD
collection
Name
CRUD
Time-Series
O
Tíme-seriescollections
efficienty
storesequernces
of measurements overa period
of [Link]
> Additionalpreferences
(e.g.
Custom collation,
Capped, Clusteredcollections)
Cancel CreateDatabase
Step 5:Open _MONGOSH and writethe commands in it.
Import Data
ONGSIH
NV Polytechnic Page 29
Step 6:Use the following
command to getintothe database
use database_name
)_MONGOSH
use PerforingCRUD
3W1tched to db Per tormingCRUD
PerformingCRUD>
command
Step 7:Use the following to Createdocuments inthe Collection
({key:value})
insertOne
db.collection_name.
)_MONGOSH
18, "Branch":"Cs"});
({"Name":"Raheman","Age":
[Link]
42ki0ledged:true,
("6563662 7cf816c967f43825")
79s2rtedic:ObjectId 2
insertMany([{key:
db.collection_name. {key:value2}])
value},
)MONGOSH
Branch":"ME"))
("Name":"Maaz","Age":10,
db. CRUD. "Name":"Vedant", "Age":15,"Branch:"Cs"),
insertMany([{
ach19wledged: true,
insertedIds:{
("656367bf7cf816c967f43826"),
'0': 0bjectId
'1': ("656367bf7cf8l6c967f43827")
ObjectId
command
Step 8: Use the following to Retrievedocuments from collection
db.collection_name.find({Age":18})
>_MONGOSH
[Link]. 2ind (("Age":18})
d: ObjectId("656366227cf816c967f43825"),
ene: 'Raheman',
NV Polytechnic Page 30
db.collection_name.find()
)MONGOSH
db, CRUD. find(0:
DujectId("656366227c f8l6c967
f43825"),
:'Raheman
eranct:'cs
Lid:objectId("656367bf7cf816c967f43826"),
Naie:'Vedant,
Agu: 15,
Branch: cs
:ObyectId("656367bf7cfS16C967f43827"),
Ne: 'Maaz',
Bri: ME
Step 9:Use the following
command documents inthe Collection
to Update the exisiting
value},
db.collection_name.updateone({key: {$set:
{key:new_value}})
>_MONGOSH
[Link] (( "Name":"Maaz" ),($set:("Branch";
CS")})
209Ludged:true,
EGtCourit:,
uDE Srt dCount:
[Link], find(("Name";"Maaz"})
23800jectid
("656367b
f7cf816c967f4
3627"),
Er unch: 'Cs
NV Polytechnic Page 31
{$set:{key:new_value}})
.updateMany({key:value},
db.collection_name
MONGOSH
"CS"),($set:("Age":18}})
eMany (("Branch";
[Link]
{
Ncinuw ledged:true,
null,
7tsertedld:
tntzbedCount: 3,
dcouot: 2,
Step 10:Use the following
command to Deletethe documents inthe Collection
({key:value})
db.collection_name.deleteOne
)_MiONGOSH
{Nane":"Vedant"})
[Link](
acknosledged:true,
deletedCount:1
():
[Link]
f8lc967f43825"),
:bjectId("656366227c
het:Raheman',
Branh: 'cs
:oDjectId
("656367b
f7cfsl6c967
f43827"),
b Maaz',
Aze: l3,
Breich:'cS
db.collection_name.deleteMany({key:value})
MONG0SH
cb. "M"))
CRUD. deleteMany ( ("Branch":
Leduud: true,
LUCotit:1
NV Polytechnic Page 32