Express middleware that logs errors to MongoDB