-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmongo_operations.py
40 lines (36 loc) · 965 Bytes
/
mongo_operations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from pydoc import cli
from pymongo import MongoClient
import pandas as pd
client = MongoClient("localhost", 27017)
print("\n Connected to ", client)
def ShowDB():
print("\n MongoDb Databases \n")
data = pd.DataFrame(list(client.list_databases()))
print(data)
def ShowCollection():
#database = input("Please Provide Database name : \n")
print("\n Collections List ")
mydatabase = client.PyDb
data = pd.DataFrame(list(mydatabase.list_collection_names()))
print(data)
def main():
choice = """
1 : Show Databases
2 : Create Database
3 : Show Collections
4 : Create Collections
5 : Find Doucuments
"""
print(choice)
Option = input("Please Choose a option:")
Option = int(Option)
try:
if Option == 1:
ShowDB()
if Option == 3:
ShowCollection()
except:
print("Sorry something went wrong !")
finally:
main()
main()