django middleware for mongodb querying analysis