0% found this document useful (0 votes)
17 views6 pages

9

The document shows operations performed on a MongoDB database including creating a collection, inserting documents, finding documents, removing documents, and querying the collection. Documents representing students are inserted into the Student collection and various queries are run to find, update and delete documents.

Uploaded by

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

9

The document shows operations performed on a MongoDB database including creating a collection, inserting documents, finding documents, removing documents, and querying the collection. Documents representing students are inserted into the Student collection and various queries are run to find, update and delete documents.

Uploaded by

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

> use Assignment1

switched to db Assignment1
> db.createCollection("Student")
{ "ok" : 1 }
> show dbs
Assignment1 0.078GB
local 0.078GB
> db.Student.insert({ Stud_id : 20, Name : "Pratik", Percentage : 85, Status :
"Present", Address : "Nashik"})
WriteResult({ "nInserted" : 1 })
> db.Student.insert({ Stud_id : 21, Name : "Shreya", Percentage : 0, Status :
"Absent", Address : "Pune"})
WriteResult({ "nInserted" : 1 })
> db.Student.insert({ Stud_id : 22, Name : "Rahul", Percentage : 70, Status :
"Present", Address : "Mumbai"})
WriteResult({ "nInserted" : 1 })
> db.Student.insert({ Stud_id : 23, Name : "Aarya", Percentage : 0, Status :
"Absent", Address : "Delhi"})
WriteResult({ "nInserted" : 1 })
> db.Student.insert({ Stud_id : 31, Name : "Pratiksha", Percentage : 77, Status :
"Present", Address : "Nashik"})
WriteResult({ "nInserted" : 1 })
> db.Student.insert({ Stud_id : 32, Name : "Vikram", Percentage : 67, Status :
"Present", Address : "Pune"})
WriteResult({ "nInserted" : 1 })
> db.Student.insert({ Stud_id : 33, Name : "Gauri", Percentage : 66, Status :
"Present", Address : "Mumbai"})
WriteResult({ "nInserted" : 1 })
> db.Student.insert({ Stud_id : 34, Name : "Rutvik", Percentage : 0, Status :
"Absent", Address : "Delhi"})
WriteResult({ "nInserted" : 1 })
> db.Student.insert({ Stud_id : 50, Name : "Aparna", Percentage : 82, Status :
"Present", Address : "Nashik"})
WriteResult({ "nInserted" : 1 })
> db.Student.insert({ Stud_id : 20, Name : "Pratik", Percentage : 0, Status :
"Absent", Address : "Pune"})
WriteResult({ "nInserted" : 1 })
> db.Student.insert({ Stud_id : 51, Name : "Kiran", Percentage : 70, Status :
"Present", Address : "Mumbai"})
WriteResult({ "nInserted" : 1 })
> db.Student.insert({ Stud_id : 52, Name : "Arjun", Percentage : 80, Status :
"Present", Address : "Delhi"})
WriteResult({ "nInserted" : 1 })
> db.Student.insert({ Stud_id : 60, Name : "Priya", Percentage : 0, Status :
"Absent", Address : "Nashik"})
WriteResult({ "nInserted" : 1 })
> db.Student.insert({ Stud_id : 61, Name : "Ravi", Percentage : 0, Status :
"Absent", Address : "Pune"})
WriteResult({ "nInserted" : 1 })
> db.Student.insert({ Stud_id : 63, Name : "Kajal", Percentage : 79, Status :
"Prsent", Address : "Mumbai"})
WriteResult({ "nInserted" : 1 })
> db.Student.insert({ Stud_id : 62, Name : "Manoj", Percentage : 81, Status :
"Present", Address : "Delhi"})
WriteResult({ "nInserted" : 1 })

/* 1. Display Collection */

> db.Student.find().pretty()
{
"_id" : ObjectId("59d3caaf5d3c093b924b0a41"),
"Stud_id" : 20,
"Name" : "Pratik",
"Percentage" : 85,
"Status" : "Present",
"Address" : "Nashik"
}
{
"_id" : ObjectId("59d3cac95d3c093b924b0a42"),
"Stud_id" : 21,
"Name" : "Shreya",
"Percentage" : 0,
"Status" : "Absent",
"Address" : "Pune"
}
{
"_id" : ObjectId("59d3cad75d3c093b924b0a43"),
"Stud_id" : 22,
"Name" : "Rahul",
"Percentage" : 70,
"Status" : "Present",
"Address" : "Mumbai"
}
{
"_id" : ObjectId("59d3caea5d3c093b924b0a44"),
"Stud_id" : 23,
"Name" : "Aarya",
"Percentage" : 0,
"Status" : "Absent",
"Address" : "Delhi"
}
{
"_id" : ObjectId("59d3caf75d3c093b924b0a45"),
"Stud_id" : 31,
"Name" : "Pratiksha",
"Percentage" : 77,
"Status" : "Present",
"Address" : "Nashik"
}
{
"_id" : ObjectId("59d3cb075d3c093b924b0a46"),
"Stud_id" : 32,
"Name" : "Vikram",
"Percentage" : 67,
"Status" : "Present",
"Address" : "Pune"
}
{
"_id" : ObjectId("59d3cb155d3c093b924b0a47"),
"Stud_id" : 33,
"Name" : "Gauri",
"Percentage" : 66,
"Status" : "Present",
"Address" : "Mumbai"
}
{
"_id" : ObjectId("59d3cb295d3c093b924b0a48"),
"Stud_id" : 34,
"Name" : "Rutvik",
"Percentage" : 0,
"Status" : "Absent",
"Address" : "Delhi"
}
{
"_id" : ObjectId("59d3cb385d3c093b924b0a49"),
"Stud_id" : 50,
"Name" : "Aparna",
"Percentage" : 82,
"Status" : "Present",
"Address" : "Nashik"
}
{
"_id" : ObjectId("59d3cb475d3c093b924b0a4a"),
"Stud_id" : 20,
"Name" : "Pratik",
"Percentage" : 0,
"Status" : "Absent",
"Address" : "Pune"
}
{
"_id" : ObjectId("59d3cb795d3c093b924b0a4b"),
"Stud_id" : 51,
"Name" : "Kiran",
"Percentage" : 70,
"Status" : "Present",
"Address" : "Mumbai"
}
{
"_id" : ObjectId("59d3cb9a5d3c093b924b0a4c"),
"Stud_id" : 52,
"Name" : "Arjun",
"Percentage" : 80,
"Status" : "Present",
"Address" : "Delhi"
}
{
"_id" : ObjectId("59d3cbaf5d3c093b924b0a4d"),
"Stud_id" : 60,
"Name" : "Priya",
"Percentage" : 0,
"Status" : "Absent",
"Address" : "Nashik"
}
{
"_id" : ObjectId("59d3cbbe5d3c093b924b0a4e"),
"Stud_id" : 61,
"Name" : "Ravi",
"Percentage" : 0,
"Status" : "Absent",
"Address" : "Pune"
}
{
"_id" : ObjectId("59d3cbe45d3c093b924b0a4f"),
"Stud_id" : 63,
"Name" : "Kajal",
"Percentage" : 79,
"Status" : "Prsent",
"Address" : "Mumbai"
}
{
"_id" : ObjectId("59d3cc075d3c093b924b0a50"),
"Stud_id" : 62,
"Name" : "Manoj",
"Percentage" : 81,
"Status" : "Present",
"Address" : "Delhi"
}

/* 2. Delete Document having Status as " Absent " and Display the Remaining
Documents */

> db.Student.remove({ Status : "Absent"})


WriteResult({ "nRemoved" : 6 })
> db.Student.find().pretty()
{
"_id" : ObjectId("59d3caaf5d3c093b924b0a41"),
"Stud_id" : 20,
"Name" : "Pratik",
"Percentage" : 85,
"Status" : "Present",
"Address" : "Nashik"
}
{
"_id" : ObjectId("59d3cad75d3c093b924b0a43"),
"Stud_id" : 22,
"Name" : "Rahul",
"Percentage" : 70,
"Status" : "Present",
"Address" : "Mumbai"
}
{
"_id" : ObjectId("59d3caf75d3c093b924b0a45"),
"Stud_id" : 31,
"Name" : "Pratiksha",
"Percentage" : 77,
"Status" : "Present",
"Address" : "Nashik"
}
{
"_id" : ObjectId("59d3cb075d3c093b924b0a46"),
"Stud_id" : 32,
"Name" : "Vikram",
"Percentage" : 67,
"Status" : "Present",
"Address" : "Pune"
}
{
"_id" : ObjectId("59d3cb155d3c093b924b0a47"),
"Stud_id" : 33,
"Name" : "Gauri",
"Percentage" : 66,
"Status" : "Present",
"Address" : "Mumbai"
}
{
"_id" : ObjectId("59d3cb385d3c093b924b0a49"),
"Stud_id" : 50,
"Name" : "Aparna",
"Percentage" : 82,
"Status" : "Present",
"Address" : "Nashik"
}
{
"_id" : ObjectId("59d3cb795d3c093b924b0a4b"),
"Stud_id" : 51,
"Name" : "Kiran",
"Percentage" : 70,
"Status" : "Present",
"Address" : "Mumbai"
}
{
"_id" : ObjectId("59d3cb9a5d3c093b924b0a4c"),
"Stud_id" : 52,
"Name" : "Arjun",
"Percentage" : 80,
"Status" : "Present",
"Address" : "Delhi"
}
{
"_id" : ObjectId("59d3cbe45d3c093b924b0a4f"),
"Stud_id" : 63,
"Name" : "Kajal",
"Percentage" : 79,
"Status" : "Prsent",
"Address" : "Mumbai"
}
{
"_id" : ObjectId("59d3cc075d3c093b924b0a50"),
"Stud_id" : 62,
"Name" : "Manoj",
"Percentage" : 81,
"Status" : "Present",
"Address" : "Delhi"
}

/* 3.Find the Student whose Status is "Present" AND Precentage is 85. */

> db.Student.find({ Status : "Present", Percentage : { $eq : 85 } } ).pretty()


{
"_id" : ObjectId("59d3caaf5d3c093b924b0a41"),
"Stud_id" : 20,
"Name" : "Pratik",
"Percentage" : 85,
"Status" : "Present",
"Address" : "Nashik"
}

/* 4.Find Student whose ID is 22. */

> db.Student.find({ Stud_id : {$eq : 22} }).pretty()


{
"_id" : ObjectId("59d3cad75d3c093b924b0a43"),
"Stud_id" : 22,
"Name" : "Rahul",
"Percentage" : 70,
"Status" : "Present",
"Address" : "Mumbai"
}

/* 5. Find whose Status is "Absent" OR Precentage is 70. */

> db.Student.find({ $or : [ { Status : "Absent" },{Percentage : { $eq :


70 } } ] } ).pretty()
{
"_id" : ObjectId("59d3cad75d3c093b924b0a43"),
"Stud_id" : 22,
"Name" : "Rahul",
"Percentage" : 70,
"Status" : "Present",
"Address" : "Mumbai"
}
{
"_id" : ObjectId("59d3cb795d3c093b924b0a4b"),
"Stud_id" : 51,
"Name" : "Kiran",
"Percentage" : 70,
"Status" : "Present",
"Address" : "Mumbai"
}

You might also like