-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
33 lines (30 loc) · 1.05 KB
/
database.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
import pandas as pd
import pymongo
from pymongo import MongoClient
#pipe agregate funtction #############################################
def get_all(data):
print('\nCreating database connection...')
client = MongoClient("localhost:27017")
db = client["assignment2"]
collection = db[data]
print('\nGetting data...')
return pd.DataFrame(list(collection.find({})))
def upload_data(df):
print('\nCreating database connection...')
conn = MongoClient("localhost:27017")
db = conn.assignment2
collection = db.hotel_reviews
print('\nTrying to insert the data...')
collection.insert_many(df.to_dict('records'))
print('\nSuccessful uploaded data')
def aggregate_fun():
print('\nCreating database connection...')
client = MongoClient("localhost:27017")
db = client["assignment2"]
print('\nApplying aggregate function...')
pipeline = [
{
"$match": { 'Total_Number_of_Reviews': { '$gt': 5000 } }
},
]
return pd.DataFrame(db.data_hotels.aggregate(pipeline))