Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Mongo Utility
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kranthi.kumar
Mongo Utility
Commits
5074e067
Commit
5074e067
authored
Jan 19, 2021
by
kranthi.kumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Basic Commit
parent
72a8bf7d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
0 deletions
+82
-0
scripts/core/mango_service.py
scripts/core/mango_service.py
+29
-0
scripts/core/mongo_handler.py
scripts/core/mongo_handler.py
+53
-0
No files found.
scripts/core/mango_service.py
0 → 100644
View file @
5074e067
from
scripts.core.mongo_handler
import
Mongo_utility
mongo_utility_object
=
Mongo_utility
()
class
Mongobd
:
@
staticmethod
def
connecting_mongodb
():
try
:
# Displaying
mongo_utility_object
.
display
(
"kranthi"
,
"user_details"
)
# searching
query
=
{
'email'
:
'cboardman4@soup.io'
}
details
=
mongo_utility_object
.
find
(
"kranthi"
,
"user_details"
,
query
)
for
values
in
details
:
print
(
values
)
# Update
query
=
{
"last_name"
:
"Hefferon"
},
{
'$set'
:
{
'last_name'
:
"Ingra"
}}
mongo_utility_object
.
update
(
"kranthi"
,
"user_details"
,
query
)
# delete
query
=
{
'email'
:
'cboardman4@soup.io'
}
mongo_utility_object
.
delete
(
"kranthi"
,
"user_details"
,
query
)
return
"process is done successfully"
except
Exception
as
e
:
print
(
e
)
Mongobd
.
connecting_mongodb
()
scripts/core/mongo_handler.py
0 → 100644
View file @
5074e067
from
pymongo
import
MongoClient
class
Mongo_utility
:
@
staticmethod
def
display
(
database_name
,
collection_name
):
try
:
client
=
MongoClient
(
'143.110.191.155'
,
37217
)
database
=
client
[
database_name
]
user_details
=
database
[
collection_name
]
# Displaying using find()
records
=
user_details
.
find
()
for
data_values
in
records
:
print
(
data_values
)
# Displaying using find_one()
print
(
user_details
.
find_one
())
except
Exception
:
return
Exception
(
"Problem in Displaying"
)
@
staticmethod
def
find
(
database_name
,
collection_name
,
query
):
try
:
client
=
MongoClient
(
'143.110.191.155'
,
37217
)
database
=
client
[
database_name
]
user_details
=
database
[
collection_name
]
return
user_details
.
find
(
query
)
except
Exception
:
return
"Problem in Searching"
@
staticmethod
def
update
(
database_name
,
collection_name
,
query
):
try
:
client
=
MongoClient
(
'143.110.191.155'
,
37217
)
database
=
client
[
database_name
]
user_details
=
database
[
collection_name
]
# Updateing one record
user_details
.
update
(
query
[
0
],
query
[
1
])
# we can Update monay records at a time by useing updateMany
except
Exception
:
return
"Problem in Updateing"
@
staticmethod
def
delete
(
database_name
,
collection_name
,
query
):
try
:
client
=
MongoClient
(
'143.110.191.155'
,
37217
)
database
=
client
[
database_name
]
user_details
=
database
[
collection_name
]
# delete single query at a time
user_details
.
delete_one
(
query
)
# We can Delete all records by useing (user_details.delete_many({}))
except
Exception
:
return
"Problem in deleteing"
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