Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
first_project
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
banashree.p
first_project
Commits
cb17923b
Commit
cb17923b
authored
Apr 06, 2022
by
banashree.p
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
subtask 1,2
parent
d182f2d7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
22 deletions
+40
-22
assignment_1mongodb/main.py
assignment_1mongodb/main.py
+8
-1
assignment_1mongodb/mongodb.py
assignment_1mongodb/mongodb.py
+32
-21
No files found.
assignment_1mongodb/main.py
View file @
cb17923b
from
idlelib.multicall
import
r
import
pymongo
import
pymongo
myclient
=
pymongo
.
MongoClient
(
"mongodb://192.168.0.220:2747/"
)
myclient
=
pymongo
.
MongoClient
(
"mongodb://192.168.0.220:2747/"
)
mydb
=
myclient
[
"bana"
]
mydb
=
myclient
[
"bana"
]
...
@@ -15,7 +17,7 @@ print(mydb.list_collection_names())
...
@@ -15,7 +17,7 @@ print(mydb.list_collection_names())
from
fastapi
import
FastAPI
from
fastapi
import
FastAPI
from
mongodb
import
mongo
from
mongodb
import
mongo
,
get_nvi
from
Repository.repo
import
getData
,
my_cursor
from
Repository.repo
import
getData
,
my_cursor
app
=
FastAPI
()
app
=
FastAPI
()
...
@@ -23,3 +25,8 @@ app = FastAPI()
...
@@ -23,3 +25,8 @@ app = FastAPI()
def
showdata
():
def
showdata
():
return
getData
()
return
getData
()
@
app
.
get
(
"/getData2"
)
def
showdata2
():
return
get_nvi
()
assignment_1mongodb/mongodb.py
View file @
cb17923b
from
pymongo
import
MongoClient
from
pymongo
import
MongoClient
def
mongo
():
def
mongo
():
# client = MongoClient('mongodb://192.168.0.220:2747/')
# client = MongoClient('mongodb://192.168.0.220:2747/')
# result = client['bana']['assignment_1'].aggregate([
# result = client['bana']['assignment_1'].aggregate([
temp
=
list
(
mycol
.
aggregate
(
temp
=
list
(
mycol
.
aggregate
(
[
[
{
{
'$project'
:
{
'$project'
:
{
'_id'
:
'$business_name'
,
'_id'
:
'$business_name'
,
'result'
:
'Violation Issued'
'result'
:
'Violation Issued'
}
}
},
{
},
{
'$group'
:
{
'$group'
:
{
'_id'
:
'$_id'
,
'_id'
:
'$_id'
,
'highest'
:
{
'highest'
:
{
'$max'
:
'$result'
'$max'
:
'$result'
}
}
}
}
},
{
},
{
'$sort'
:
{
'$sort'
:
{
'highest'
:
-
1
'highest'
:
-
1
}
}
}
}
]))
]))
return
(
temp
[
0
])
return
(
temp
[
0
])
# Requires the PyMongo package.
# Requires the PyMongo package.
# https://api.mongodb.com/python/current
# https://api.mongodb.com/python/current
from
main
import
mydb
,
mycol
from
main
import
mydb
,
mycol
# mydb.teams.find().sort({result:-1}).limit(1)
\ No newline at end of file
# mydb.teams.find().sort({result:-1}).limit(1)
def
get_nvi
():
r
=
mycol
.
find
({
"result"
:
"No Violation Issued"
})
lst
=
[]
for
i
in
r
:
lst
.
append
(
i
[
"business_name"
])
return
lst
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