Error handling for MongoDB