-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhandler.py
More file actions
32 lines (24 loc) · 782 Bytes
/
handler.py
File metadata and controls
32 lines (24 loc) · 782 Bytes
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
import pymongo
import os
MONGODB_URL = os.environ['MONGODB_URL']
MONGODB_DB = os.environ["MONGODB_DB"]
MONGODB_COL = os.environ["MONGODB_COL"]
INSERT_ROWS = 10000
client = pymongo.MongoClient(MONGODB_URL)
def reader(event, context):
db = client[MONGODB_DB]
testCol = db[MONGODB_COL]
cursor = testCol.find({})
rowCount = 0
for row in cursor:
rowCount += 1
print(row)
print('Total rows retrieved {}'.format(rowCount))
def writer(event, context):
db = client[MONGODB_DB]
testCol = db[MONGODB_COL]
rowCount = 0
for rowNum in range(INSERT_ROWS):
testCol.insert_one({"rowNum": rowNum, "title": "json-data", "author": "dhaval nagar", "body": "Lorem ipsum dolor sit amet."})
rowCount += 1
print('Total rows written {}'.format(rowCount))