forked from dakshvar22/DishingOut
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabase.py
43 lines (30 loc) · 1.04 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
34
35
36
37
38
39
40
41
42
43
__author__ = 'daksh'
from pymongo import MongoClient
class MongoOperator():
def __init__(self,db):
self.dbName = db
def setUpConnection(self):
self.client = MongoClient('localhost', 27017)
self.db = self.client[self.dbName]
def setUpCollection(self,collName):
if(collName in self.db.collection_names()):
self.collection = self.db.get_collection(collName)
else:
self.db.create_collection(collName)
self.collection = self.db.get_collection(collName)
def getOne(self):
print(self.collection.find_one())
def getAll(self):
return self.collection.find({})
def insertOne(self,res):
self.collection.insert_one(res)
def insertMany(self,listofRes):
self.collection.insert_many(listofRes)
def closeConnection(self):
self.client.close()
if __name__ == '__main__':
mongo = MongoOperator('DishingOut')
mongo.setUpConnection()
mongo.setUpCollection('reviews')
reviews = mongo.getAll()
print(reviews[20])