Recently a challenge from CSIT arose. The challenge is to build a backend in any language to query information from the Database based on a set of input queries.
Broadly the task can be broken into 4 broad steps. Firstly it is to validate the input query to make sure the inputs are healthy. Following which, we would need to query the relevant information from the backend and finally present the results to the user. The final step is to dockerise this technology.
Have a look at the challenge here: https://se-mini-challenge.csit-events.sg/
Step 0: Set up the app
Let’s make a simple application in Flask. First create a virtual environment. You may follow this guide.
mkdir venv
python3 -m venv venv
source venv/bin/activate
Let’s build the app, import the following:
#!/usr/bin/env python
import flask
from flask import request, Response, jsonify
from pymongo import MongoClient
import sys
import datetime
import json
Let’s connect to the MongoDB:
client = MongoClient()
client = MongoClient("mongodb+srv://userReadOnly:7ZT817O8ejDfhnBM@minichallenge.q4nve1r.mongodb.net", 27017)
db = client.minichallenge