0% found this document useful (0 votes)
51 views4 pages

Untitled

The document shows the output of various commands run in the MongoDB shell. It connects to a MongoDB database, creates collections, inserts documents, runs aggregation queries to group and calculate totals, creates indexes on fields, and drops indexes.

Uploaded by

Akshata Chopade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views4 pages

Untitled

The document shows the output of various commands run in the MongoDB shell. It connects to a MongoDB database, creates collections, inserts documents, runs aggregation queries to group and calculate totals, creates indexes on fields, and drops indexes.

Uploaded by

Akshata Chopade
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 4

ubuntu@ubuntu-OptiPlex-390:~$ mongo

MongoDB shell version v3.6.8


connecting to: mongodb://127.0.0.1:27017
Implicit session: session { "id" : UUID("ecfc80bb-047e-4be6-a028-c802ca6292fe") }
MongoDB server version: 3.6.8
Server has startup warnings:
2022-11-01T14:50:36.408+0530 I STORAGE [initandlisten]
2022-11-01T14:50:36.408+0530 I STORAGE [initandlisten] ** WARNING: Using the XFS
filesystem is strongly recommended with the WiredTiger storage engine
2022-11-01T14:50:36.408+0530 I STORAGE [initandlisten] ** See
http://dochub.mongodb.org/core/prodnotes-filesystem
2022-11-01T14:50:41.345+0530 I CONTROL [initandlisten]
2022-11-01T14:50:41.345+0530 I CONTROL [initandlisten] ** WARNING: Access control is not
enabled for the database.
2022-11-01T14:50:41.345+0530 I CONTROL [initandlisten] ** Read and write access to
data and configuration is unrestricted.
2022-11-01T14:50:41.345+0530 I CONTROL [initandlisten]
> use anisha10;
switched to db anisha10;
> db.createCollection('website');
{ "ok" : 1 }
> db.website.insert({'rno':'1','name':'sakshi','amount':'1000','URL':'www.yahoo.com'});
WriteResult({ "nInserted" : 1 })
> db.website.insert({'rno':'2','name':'harsh','amount':'2000','URL':'www.google.com'});
WriteResult({ "nInserted" : 1 })
> db.website.insert({'rno':'3','name':'manav','amount':'3000','URL':'www.gmail.com'});
WriteResult({ "nInserted" : 1 })
> db.website.insert({'rno':'4','name':'ravi','amount':'2000','URL':'www.gmail.com'});
WriteResult({ "nInserted" : 1 })
> db.website.insert({'rno':'5','name':'ash','amount':'4000','URL':'www.sinhgad.com'});
WriteResult({ "nInserted" : 1 })
> db.website.insert({'rno':'6','name':'ash','amount':'1000','URL':'www.sinhgad.com'});
WriteResult({ "nInserted" : 1 })
> db.website.aggregate({$group:{_id:"$name","total":{$sum:"$amount"}}});
{ "_id" : "ash", "total" : 0 }
{ "_id" : "ravi", "total" : 0 }
{ "_id" : "manav", "total" : 0 }
{ "_id" : "harsh", "total" : 0 }
{ "_id" : "anisha", "total" : 0 }

> db.stud.aggregate({$group:{_id:"$name","total":{$sum:1}}});
{ "_id" : "Shivani", "total" : 2 }
{ "_id" : "Shweta", "total" : 1 }
{ "_id" : "Shreya", "total" : 1 }
{ "_id" : "Shivu", "total" : 1 }
{ "_id" : "Shraddha", "total" : 1 }

> db.stud.aggregate({$group:{_id:"$name","total":{$max:"$amt"}}});
{ "_id" : "Shivani", "total" : "5000" }
{ "_id" : "Shweta", "total" : "2000" }
{ "_id" : "Shreya", "total" : "3000" }
{ "_id" : "Shivu", "total" : "2000" }
{ "_id" : "Shraddha", "total" : "1000" }

> db.stud.aggregate({$group:{_id:"$name","total":{$min:"$amt"}}});
{ "_id" : "Shivani", "total" : "1000" }
{ "_id" : "Shweta", "total" : "2000" }
{ "_id" : "Shreya", "total" : "3000" }
{ "_id" : "Shivu", "total" : "2000" }
{ "_id" : "Shraddha", "total" : "1000" }

> db.stud.aggregate({$group:{_id:"$name","total":{$first:"$amt"}}});
{ "_id" : "Shivani", "total" : "1000" }
{ "_id" : "Shweta", "total" : "2000" }
{ "_id" : "Shreya", "total" : "3000" }
{ "_id" : "Shivu", "total" : "2000" }
{ "_id" : "Shraddha", "total" : "1000" }

> db.stud.aggregate({$group:{_id:"$name","total":{$last:"$amt"}}});
{ "_id" : "Shivani", "total" : "5000" }
{ "_id" : "Shweta", "total" : "2000" }
{ "_id" : "Shreya", "total" : "3000" }
{ "_id" : "Shivu", "total" : "2000" }
{ "_id" : "Shraddha", "total" : "1000" }

> db.createCollection('Website2');
{ "ok" : 1 }
> db.Website2.insert({'rollno':'1','name':'Shraddha'});
WriteResult({ "nInserted" : 1 })
> db.Website2.insert({'rollno':'1','name':'Shraddha'});
WriteResult({ "nInserted" : 1 })
> db.Website2.find().pretty();
{
"_id" : ObjectId("6360f576c28b18142ad348e8"),
"rollno" : "1",
"name" : "Shraddha"
}
{
"_id" : ObjectId("6360f57bc28b18142ad348e9"),
"rollno" : "1",
"name" : "Shraddha"
}
>

> db.Website2.createIndex({'name':1});
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 1,
"numIndexesAfter" : 2,
"ok" : 1
}
> db.Website2.createIndex({'name':-1});
{
"createdCollectionAutomatically" : false,
"numIndexesBefore" : 2,
"numIndexesAfter" : 3,
"ok" : 1
}

> db.Website2.getIndices();
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "shivani.Website2"
},
{
"v" : 2,
"key" : {
"name" : 1
},
"name" : "name_1",
"ns" : "shivani.Website2"
},
{
"v" : 2,
"key" : {
"name" : -1
},
"name" : "name_-1",
"ns" : "shivani.Website2"
}
]

> db.Website2.dropIndex({'name':1});
{ "nIndexesWas" : 3, "ok" : 1 }
> db.Website2.getIndices();
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "shivani.Website2"
},
{
"v" : 2,
"key" : {
"name" : -1
},
"name" : "name_-1",
"ns" : "shivani.Website2"
}
]
> db.Website2.dropIndex({'name':-1});
{ "nIndexesWas" : 2, "ok" : 1 }
> db.Website2.getIndices();
[
{
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_",
"ns" : "shivani.Website2"
}
]
>

You might also like