Use Flask-PyMongo instead of pymongo, which has better integration with Flask.

Introduce unit testing.