from pymongo import MongoClient


def mongo():
    # client = MongoClient('mongodb://192.168.0.220:2747/')
    # result = client['bana']['assignment_1'].aggregate([
    temp = list(mycol.aggregate(
        [
            {
                '$project': {
                    '_id': '$business_name',
                    'result': 'Violation Issued'
                }
            }, {
            '$group': {
                '_id': '$_id',
                'highest': {
                    '$max': '$result'
                }
            }
        }, {
            '$sort': {
                'highest': -1
            }
        }
        ]))
    return (temp[0])


# Requires the PyMongo package.
# https://api.mongodb.com/python/current
from main import mydb, mycol


# mydb.teams.find().sort({result:-1}).limit(1)
def get_nvi():
    r = mycol.find({"result": "No Violation Issued"})
    lst = []
    for i in r:
        lst.append(i["business_name"])
    return lst
