Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mongo
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mohammed.shibili
mongo
Commits
83558508
Commit
83558508
authored
Feb 06, 2023
by
mohammed.shibili
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updates done
parent
756e82db
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
73 additions
and
60 deletions
+73
-60
.idea/sonarlint/issuestore/index.pb
+4
-0
script/core/handlers/deleting.py
+2
-1
script/core/handlers/finding.py
+2
-1
script/core/handlers/inserting.py
+11
-3
script/core/handlers/operation_to_perform.py
+47
-0
script/core/handlers/update.py
+4
-1
script/servieces/accept_data.py
+3
-54
No files found.
.idea/sonarlint/issuestore/index.pb
View file @
83558508
No preview for this file type
script/core/handlers/deleting.py
View file @
83558508
# delete for mongodb
def
deleting
(
id_to_delete
,
coll_name
):
def
deleting
(
coll_name
):
id_to_delete
=
input
(
"enter the id to deleted"
)
try
:
coll_name
.
delete_many
({
'id'
:
id_to_delete
})
except
Exception
as
e
:
...
...
script/core/handlers/finding.py
View file @
83558508
# view for mongodb
def
finding
(
id_to_find
,
coll_name
):
def
finding
(
coll_name
):
id_to_find
=
int
(
input
(
"enter the id to find"
))
try
:
element_found
=
coll_name
.
find_one
({
"emp_id"
:
id_to_find
},
{
"_id"
:
0
})
print
(
element_found
)
...
...
script/core/handlers/inserting.py
View file @
83558508
# insertion for mongodb
def
inserting
(
datas_list
,
coll_name
):
employee
=
datas_list
def
inserting
(
coll_name
):
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
)
try
:
coll_name
.
insert_many
(
employee
)
coll_name
.
insert_many
(
data_list
)
except
Exception
as
e
:
print
(
e
,
"data not inserted"
)
...
...
script/core/handlers/operation_to_perform.py
0 → 100644
View file @
83558508
from
script.core.handlers.deleting
import
deleting
,
post_delete
from
script.core.handlers.finding
import
finding
,
postgres_search
from
script.core.handlers.inserting
import
inserting
,
post_insert
from
script.core.handlers.update
import
updating
,
post_update
def
to_mongo
(
coll_name
):
print
(
"1.insert
\n
2.update
\n
3.delete
\n
4.read"
)
operation
=
int
(
input
(
"enter the operation to perform"
))
# inserting operation
if
operation
==
1
:
inserting
(
coll_name
)
# update operation
elif
operation
==
2
:
updating
(
coll_name
)
# delete operation
elif
operation
==
3
:
deleting
(
coll_name
)
# view operation
elif
operation
==
4
:
finding
(
coll_name
)
def
to_postgres
(
connection
,
cursor_name
):
print
(
"1.insert
\n
2.update
\n
3.delete
\n
4.read"
)
operation
=
int
(
input
(
"enter the operation to perform"
))
# creating table on postgresql
query
=
"""
CREATE TABLE emp_table11 (
id INTEGER PRIMARY KEY,
name VARCHAR(255) NOT NULL,
age INTEGER NOT NULL,
salary INTEGER NOT NULL
);
"""
# accepting operation to be performed
cursor_name
.
execute
(
query
)
connection
.
commit
()
if
operation
==
1
:
post_insert
(
connection
,
cursor_name
)
elif
operation
==
2
:
post_update
(
connection
,
cursor_name
)
elif
operation
==
3
:
post_delete
(
connection
,
cursor_name
)
elif
operation
==
4
:
postgres_search
(
connection
,
cursor_name
)
\ No newline at end of file
script/core/handlers/update.py
View file @
83558508
# update for mongodb
def
updating
(
id_to_search
,
field_to_update
,
element_tobe_updated
,
coll_name
):
def
updating
(
coll_name
):
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"
)
update
=
{
"$set"
:
{
field_to_update
:
element_tobe_updated
}}
try
:
coll_name
.
update_one
({
"emp_id"
:
id_to_search
},
update
)
...
...
script/servieces/accept_data.py
View file @
83558508
from
script.core.handlers.deleting
import
deleting
,
post_delete
from
script.core.handlers.finding
import
finding
,
postgres_search
from
script.core.handlers.inserting
import
inserting
,
post_insert
from
script.core.handlers.update
import
updating
,
post_update
from
script.core.handlers.operation_to_perform
import
to_mongo
,
to_postgres
# function for operation of mongodb
def
user_data
(
coll_name
):
print
(
"1.insert
\n
2.update
\n
3.delete
\n
4.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
)
# delete operation
elif
operation
==
3
:
id_to_delete
=
input
(
"enter the id to deleted"
)
deleting
(
id_to_delete
,
coll_name
)
# view operation
elif
operation
==
4
:
id_to_find
=
int
(
input
(
"enter the id to find"
))
finding
(
id_to_find
,
coll_name
)
to_mongo
(
coll_name
)
# function for operation of mongodb
def
user_postgres
(
connection
,
cursor_name
):
print
(
"1.insert
\n
2.update
\n
3.delete
\n
4.read"
)
operation
=
int
(
input
(
"enter the operation to perform"
))
# creating table on postgresql
query
=
"""
CREATE TABLE emp_table11 (
id INTEGER PRIMARY KEY,
name VARCHAR(255) NOT NULL,
age INTEGER NOT NULL,
salary INTEGER NOT NULL
);
"""
# accepting operation to be performed
cursor_name
.
execute
(
query
)
connection
.
commit
()
if
operation
==
1
:
post_insert
(
connection
,
cursor_name
)
elif
operation
==
2
:
post_update
(
connection
,
cursor_name
)
elif
operation
==
3
:
post_delete
(
connection
,
cursor_name
)
elif
operation
==
4
:
postgres_search
(
connection
,
cursor_name
)
to_postgres
(
connection
,
cursor_name
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment