0% found this document useful (0 votes)
15 views3 pages

MongoDB Student Record Management

DBMS

Uploaded by

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

MongoDB Student Record Management

DBMS

Uploaded by

pamate1130
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Practical no :- 8

import pymongo
client=[Link]("mongodb://localhost:27017") db=client["student"]
collection=db["stud"]

def create_data():
r=int(input("Enter roll no: ")) n=input("Enter name: ") m=input("Enter Marks: ")
data={"Roll No":r,"Name":n,"Marks":m} insert_doc=collection.insert_one(data) print("Record
Inserted")

def show(): show_data=[Link]() for data in


show_data: print(data)

def update(): r=int(input("Enter roll no to Update: ")) m=input("Enter Marks: ")


update_multiple = collection.update_many({"Roll No": r}, {"$set":{ "Marks":
m}})
print(update_multiple) condition={"Roll No":r} val={"$set":{"Marks":m}}
update_single = collection.update_one(condition,val) print(update_single)

def delete():
r=int(input("Enter roll no to Delete: ")) delt={"Roll No": r} collection.delete_one(delt)
print("Record Deleted Roll No:",r)

while True:
print("\nMAIN MENU") print("1. Insert") print("2. Update") print("3. Delete")
print("4. Display") print("5. Exit")
choice = int(input("Enter the

Choice:")) if choice == 1: create_data()

elif choice == 2: update()

elif choice == 3: delete()

elif choice == 4:
show()

elif choice == 5: break else:


print("Oops! Incorrect Choice.")

OUTPUT

MAIN MENU
1. Insert
2. Update
3. Delete
4. Display
5. Exit
Enter the Choice:1
Enter roll no: 1
Enter name: Naitik
Enter Marks: 95
Record Inserted

MAIN MENU
1. Insert
2. Update
3. Delete
4. Display
5. Exit
Enter the Choice:1
Enter roll no: 2
Enter name: Abhi
Enter Marks: 88
Record Inserted

MAIN MENU
1. Insert
2. Update
3. Delete
4. Display
5. Exit
Enter the Choice:1
Enter roll no: 3
Enter name: Dinesh
Enter Marks: 90
Record Inserted

MAIN MENU
1. Insert
2. Update
3. Delete
4. Display
5. Exit
Enter the Choice:1
Enter roll no: 4
Enter name: Priyanka
Enter Marks: 85
Record Inserted

MAIN MENU
1. Insert
2. Update
3. Delete
4. Display 5. Exit
Enter the Choice:4 {’_id’: ObjectId(’653fbb8abc2b7a22aeb391be’), ’Roll N o’: 1, ’Name’: ’Naitik’,
’Marks’: ’95’}
{’_id’: ObjectId(’653fbbd6963e22ae493019b8’), ’Roll N o’: 2, ’Name’: ’Abhi’, ’Marks’: ’88’}
{’_id’: ObjectId(’653fbbf9963e22ae493019b9’), ’Roll N o’: 3, ’Name’: ’Dinesh’, ’Marks’: ’90’}
{’_id’: ObjectId(’653fbc27963e22ae493019ba’), ’Roll N o’: 4, ’Name’: ’Priyanka’, ’Marks’: ’85’}

MAIN MENU
1. Insert
2. Update
3. Delete
4. Display
5. Exit
Enter the Choice:3
Enter roll no to
Delete:3
Record Deleted Roll No: 3

MAIN MENU
1. Insert
2. Update
3. Delete
4. Display
5. Exit
Enter the Choice:4
{’_id’: ObjectId(’653fbb8abc2b7a22aeb391be’), ’Roll N o’: 1, ’Name’: ’Naitik’, ’Marks’: ’95’}
{’_id’: ObjectId(’653fbbd6963e22ae493019b8’), ’Roll N o’: 2, ’Name’: ’Abhi’, ’Marks’: ’88’}
{’_id’: ObjectId(’653fbc27963e22ae493019ba’), ’Roll N o’: 4, ’Name’: ’Priyanka’, ’Marks’: ’85’}

MAIN MENU
1. Insert
2. Update
3. Delete
4. Display
5. Exit
Enter the Choice:5

You might also like