Skip to content

Commit 53f9020

Browse files
authored
Merge pull request #8 from fonk-apps/delete_function
New delete function, implemented with Fission/Python
2 parents ad26b4d + d14f694 commit 53f9020

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
pip3 install -r ${SRC_PKG}/requirements.txt -t ${SRC_PKG} && cp -r ${SRC_PKG} ${DEPLOY_PKG}
3+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pymongo
2+
import json
3+
4+
from flask import request, Flask, Response
5+
6+
MONGODB_HOST = "fonkdb-mongodb.default"
7+
MONGODB_PORT = 27017
8+
MONGODB_NAME = "guestbook_app"
9+
MONGODB_COLLECTION = "entries"
10+
11+
def main():
12+
try:
13+
client = pymongo.MongoClient("mongodb://{}".format(MONGODB_HOST), int(MONGODB_PORT))
14+
collection = client[MONGODB_NAME][MONGODB_COLLECTION]
15+
result = collection.remove({})
16+
return response(json.dumps(result,indent=2), 200)
17+
except pymongo.errors.PyMongoError as err:
18+
return response({"error": "MongoDB error: " + str(err)}, 500)
19+
except Exception as err:
20+
return response({"error": str(err)}, 500)
21+
22+
def response(body, status):
23+
return Response(str(body), status, {"Content-Type": "application/json", "Access-Control-Allow-Origin": "*"})
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pymongo
2+

0 commit comments

Comments
 (0)