mongo middleware