Commit e66200b6 by mohammed.shibili

mongo cred

parents
# Default ignored files
/shelf/
/workspace.xml
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (mongo)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/mongo.iml" filepath="$PROJECT_DIR$/.idea/mongo.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
from script.core.engine.connecton import app_call
from script.servieces.accept_data import user_data
coll_name = app_call()
user_data(coll_name)
[data_base]
server=mongodb://localhost:27017
database =employee_db
collection =employees
\ No newline at end of file
import configparser
config = configparser.ConfigParser()
config.read("conf/dbconf.conf")
server_name = config.get("data_base", "server")
db_name = config.get("data_base", "database")
collection_name = config.get("data_base", "collection")
from pymongo import MongoClient
from script.configuration.databaseconfig import db_name, server_name, collection_name
def app_call():
client = MongoClient(server_name)
database = client[db_name]
collection = database[collection_name]
return collection
def deleting(id_to_delete, coll_name):
try:
coll_name.delete_many({'id': id_to_delete})
except Exception as e:
print(e, "not deleted")
def finding(id_to_find, coll_name):
try:
element_found = coll_name.find_one({"emp_id": id_to_find}, {"_id": 0})
print(element_found)
except Exception as e:
print(e, "not found")
def inserting(datas_list, coll_name):
employee = datas_list
try:
coll_name.insert_many(employee)
except Exception as e:
print(e, "data not inserted")
def updating(id_to_search, field_to_update, element_tobe_updated, coll_name):
update = {"$set": {field_to_update: element_tobe_updated}}
try:
coll_name.update_one({"emp_id": id_to_search}, update)
except Exception as e:
print(e, "updation failed")
from script.core.handlers.deleting import deleting
from script.core.handlers.finding import finding
from script.core.handlers.inserting import inserting
from script.core.handlers.update import updating
def user_data(coll_name):
print("1.insert \n2.update\n3.delete\n4.read")
operation = int(input("enter the operation to perform"))
# inserting operation
if operation == 1:
fields = int(input("enter the number of fields"))
data_list = []
datas_to_insert = {}
while fields > 0:
key = input("enter the colum heading")
value = input("enter the value")
datas_to_insert[key] = value
fields = fields - 1
data_list.append(datas_to_insert)
inserting(data_list, coll_name)
# update operation
elif operation == 2:
id_to_search = int(input("enter the id to search"))
field_to_update = input("enter the field to update")
element_tobe_updated = input("enter the value to be updated")
updating(id_to_search, field_to_update, element_tobe_updated, coll_name)
elif operation == 3:
id_to_delete = input("enter the id to deleted")
deleting(id_to_delete, coll_name)
elif operation == 4:
id_to_find =int(input("enter the id to find"))
finding(id_to_find, coll_name)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment