if connection is not None:
    database['test'].insert({'name': 'foo'})
doc = database['test'].find_one({'name': 'foo'})
return json.dumps(doc, sort_keys=True, indent=4, default=json_util.default)
How do I turn MongoDB query into a JSON?